Example usage for com.google.gwt.user.client.ui CheckBox getValue

List of usage examples for com.google.gwt.user.client.ui CheckBox getValue

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui CheckBox getValue.

Prototype

@Override
public Boolean getValue() 

Source Link

Document

Determines whether this check box is currently checked.

Usage

From source file:org.rstudio.studio.client.projects.model.ProjectTemplateWidget.java

License:Open Source License

private ProjectTemplateWidgetItem checkBoxInput(final ProjectTemplateWidgetDescription description) {
    final CheckBox widget = new CheckBox(description.getLabel());

    // set default value
    String defaultValue = description.getDefault();
    if (!StringUtil.isNullOrEmpty(defaultValue))
        widget.setValue(isTruthy(defaultValue));

    return new ProjectTemplateWidgetItem(widget, new Collector() {
        @Override//  w ww . j a va  2 s  .  c  o  m
        public void collectInput(JsObject receiver) {
            boolean value = widget.getValue();
            receiver.setBoolean(description.getParameter(), value);
        }
    });
}

From source file:org.rstudio.studio.client.workbench.prefs.views.EditingPreferencesPane.java

License:Open Source License

private void addEnabledDependency(final CheckBox speaker, final CheckBox listener) {
    if (speaker.getValue() == false)
        disable(listener);//from   w  ww.  j  av  a  2s .c  o  m

    speaker.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            if (event.getValue() == false)
                disable(listener);
            else
                enable(listener);
        }
    });
}

From source file:org.rstudio.studio.client.workbench.prefs.views.PreferencesPane.java

License:Open Source License

protected CheckBox checkboxPref(String label, final PrefValue<Boolean> prefValue, String title) {
    final CheckBox checkBox = new CheckBox(label, false);
    lessSpaced(checkBox);// w  w  w. j a  v  a2s  . com
    checkBox.setValue(prefValue.getGlobalValue());
    if (title != null)
        checkBox.setTitle(title);
    onApplyCommands_.add(new Command() {
        public void execute() {
            prefValue.setGlobalValue(checkBox.getValue());
        }
    });
    return checkBox;
}

From source file:org.silverpeas.mobile.client.apps.workflow.pages.widgets.FieldEditable.java

License:Open Source License

@Override
public void onValueChange(final ValueChangeEvent valueChangeEvent) {
    String value = "";
    if (valueChangeEvent.getSource() instanceof RadioButton) {
        value = ((RadioButton) valueChangeEvent.getSource()).getText();
    } else if (valueChangeEvent.getSource() instanceof CheckBox) {
        FlowPanel p = (FlowPanel) ((CheckBox) valueChangeEvent.getSource()).getParent();
        for (int i = 0; i < p.getWidgetCount(); i++) {
            CheckBox c = (CheckBox) p.getWidget(i);
            if (c.getValue()) {
                value += c.getName() + ",";
            }/*from w ww  .j a v  a2s . c o m*/
        }
        if (value.indexOf(",") != -1) {
            value = value.substring(0, value.length() - 1);
        }
    }
    data.setValue(value);
}

From source file:org.thechiselgroup.biomixer.client.BioMixerViewWindowContentProducer.java

License:Apache License

private VerticalPanel createArcTypeContainerControl(String label, final ArcItemContainer arcItemContainer) {

    final TextBox arcColorText = new TextBox();
    arcColorText.setText(arcItemContainer.getArcColor());

    final ListBox arcStyleDropDown = new ListBox();
    arcStyleDropDown.setVisibleItemCount(1);
    arcStyleDropDown.addItem(ArcSettings.ARC_STYLE_SOLID);
    arcStyleDropDown.addItem(ArcSettings.ARC_STYLE_DASHED);
    arcStyleDropDown.addItem(ArcSettings.ARC_STYLE_DOTTED);
    String arcStyle = arcItemContainer.getArcStyle();
    if (ArcSettings.ARC_STYLE_DOTTED.equals(arcStyle)) {
        arcStyleDropDown.setSelectedIndex(2);
    } else if (ArcSettings.ARC_STYLE_DASHED.equals(arcStyle)) {
        arcStyleDropDown.setSelectedIndex(1);
    } else {//from  w  w  w. ja va  2  s .  c  om
        arcStyleDropDown.setSelectedIndex(0);
    }

    final ListBox arcHeadDropDown = new ListBox();
    arcHeadDropDown.setVisibleItemCount(1);
    arcHeadDropDown.addItem(ArcSettings.ARC_HEAD_NONE);
    arcHeadDropDown.addItem(ArcSettings.ARC_HEAD_TRIANGLE_EMPTY);
    arcHeadDropDown.addItem(ArcSettings.ARC_HEAD_TRIANGLE_FULL);
    String arcHead = arcItemContainer.getArcHead();
    if (ArcSettings.ARC_HEAD_TRIANGLE_FULL.equals(arcHead)) {
        arcHeadDropDown.setSelectedIndex(2);
    } else if (ArcSettings.ARC_HEAD_TRIANGLE_EMPTY.equals(arcHead)) {
        arcHeadDropDown.setSelectedIndex(1);
    } else if (ArcSettings.ARC_HEAD_NONE.equals(arcHead)) {
        arcHeadDropDown.setSelectedIndex(0);
    }

    final String defaultEntry = "Default";
    final ListBox arcThicknessDropDown = new ListBox();
    arcThicknessDropDown.setVisibleItemCount(1);
    arcThicknessDropDown.addItem(defaultEntry);
    arcThicknessDropDown.addItem("1");
    arcThicknessDropDown.addItem("2");
    arcThicknessDropDown.addItem("3");
    arcThicknessDropDown.addItem("4");
    arcThicknessDropDown.addItem("5");
    arcThicknessDropDown.setSelectedIndex(0);

    final Button updateButton = new Button("Update Arcs");
    updateButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            arcItemContainer.setArcColor(arcColorText.getText());
            arcItemContainer.setArcStyle(arcStyleDropDown.getItemText(arcStyleDropDown.getSelectedIndex()));

            String selectedThicknessText = arcThicknessDropDown
                    .getItemText(arcThicknessDropDown.getSelectedIndex());
            if (selectedThicknessText.equals(defaultEntry)) {
                arcItemContainer.setArcThicknessLevel(0);
            } else {
                arcItemContainer.setArcThicknessLevel(Integer.parseInt(selectedThicknessText));
            }

            arcItemContainer.setArcHead(arcHeadDropDown.getItemText(arcHeadDropDown.getSelectedIndex()));

        }
    });

    final CheckBox visibleCheckBox = new CheckBox("Arcs Visible");
    visibleCheckBox.setValue(true);
    visibleCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean value = visibleCheckBox.getValue();
            updateButton.setEnabled(value);
            arcStyleDropDown.setEnabled(value);
            arcHeadDropDown.setEnabled(value);
            arcThicknessDropDown.setEnabled(value);
            arcColorText.setEnabled(value);
            arcItemContainer.setVisible(value);
        }

    });

    VerticalPanel containerPanel = new VerticalPanel();

    containerPanel.add(new Label(label));
    containerPanel.add(visibleCheckBox);
    containerPanel.add(new Label("Arc Color"));
    containerPanel.add(arcColorText);
    containerPanel.add(new Label("Arc Style"));
    containerPanel.add(arcStyleDropDown);
    containerPanel.add(new Label("Arc Head"));
    containerPanel.add(arcHeadDropDown);
    containerPanel.add(new Label("Arc Thickness"));
    containerPanel.add(arcThicknessDropDown);
    containerPanel.add(updateButton);

    // Handler runs and removes itself internally.
    @SuppressWarnings("unused")
    Handler handler = new Handler() {
        private HandlerRegistration register = arcColorText.addAttachHandler(this);

        @Override
        public void onAttachOrDetach(AttachEvent event) {
            $(arcColorText).as(Enhance).colorBox(ColorPickerType.SIMPLE);
            // Only want this run once, so let's do a trick to remove it.
            register.removeHandler();
        }
    };

    return containerPanel;
}

From source file:org.thechiselgroup.biomixer.client.BioMixerViewWindowContentProducer.java

License:Apache License

private SidePanelSection createOntologyGraphNodesSidePanelSection(final ResourceModel resourceModel,
        final VisualizationModel visualizationModel) {

    final VerticalPanel panel = new VerticalPanel();

    final Map<String, CheckBox> ontologyToFilterBox = CollectionFactory.createStringMap();

    final CheckBox colorByOntologyCheckBox = new CheckBox("Color Nodes by Ontology");
    colorByOntologyCheckBox.setValue(true);
    colorByOntologyCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override//from  w w w  .jav  a2s .  c om
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean value = colorByOntologyCheckBox.getValue();

            VisualItemValueResolver resolver;
            if (value) {
                resolver = NODE_COLOR_BY_ONTOLOGY_RESOLVER_FACTORY.create();
            } else {
                resolver = NODE_BACKGROUND_COLOR_RESOLVER_FACTORY.create();
            }

            visualizationModel.setResolver(Graph.NODE_BACKGROUND_COLOR, resolver);
        }
    });

    resourceModel.getResources().addEventHandler(new ResourceSetChangedEventHandler() {
        @Override
        public void onResourceSetChanged(ResourceSetChangedEvent event) {
            LightweightCollection<Resource> addedResources = event.getAddedResources();
            for (Resource resource : addedResources) {
                if (Ontology.isOntology(resource)) {
                    String ontologyAcronym = (String) resource.getValue(Ontology.ONTOLOGY_ACRONYM);
                    if (!ontologyToFilterBox.containsKey(ontologyAcronym)) {

                        CheckBox checkBox = new CheckBox("<span style='color: "
                                + BioMixerConceptByOntologyColorResolver.getColor(ontologyAcronym)
                                + "'>&#9609;</span>" + "&nbsp;" + "Show "
                                + resource.getValue(Ontology.ONTOLOGY_ACRONYM), true);
                        checkBox.setValue(true);
                        ontologyToFilterBox.put(ontologyAcronym, checkBox);
                        panel.add(checkBox);
                        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                            @Override
                            public void onValueChange(ValueChangeEvent<Boolean> event) {
                                updatePredicate(resourceModel, false, ontologyToFilterBox);
                            }
                        });
                    }
                }
            }
        }
    });

    panel.add(colorByOntologyCheckBox);

    updatePredicate(resourceModel, false, ontologyToFilterBox);

    return new SidePanelSection("Nodes", panel);
}

From source file:org.thechiselgroup.biomixer.client.BioMixerViewWindowContentProducer.java

License:Apache License

private SidePanelSection createConceptGraphNodesSidePanelSection(final ResourceModel resourceModel,
        final VisualizationModel visualizationModel) {

    final VerticalPanel panel = new VerticalPanel();

    final Map<String, CheckBox> ontologyToFilterBox = CollectionFactory.createStringMap();

    // code below removes the "Show Mapping Nodes" checkbox under the
    // "Nodes" view part in the vertical panel
    // final CheckBox mappingNodesCheckbox = new
    // CheckBox("Show Mapping Nodes");
    // mappingNodesCheckbox.setValue(false);
    // mappingNodesCheckbox
    // .addValueChangeHandler(new ValueChangeHandler<Boolean>() {
    // @Override/*from  www  . j  a  va2  s .c o m*/
    // public void onValueChange(ValueChangeEvent<Boolean> event) {
    // updatePredicate(resourceModel,
    // mappingNodesCheckbox.getValue(),
    // ontologyToFilterBox);
    // }
    // });

    final CheckBox colorByOntologyCheckBox = new CheckBox("Color Concept Nodes by Ontology");
    colorByOntologyCheckBox.setValue(true);
    colorByOntologyCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            boolean value = colorByOntologyCheckBox.getValue();

            VisualItemValueResolver resolver;
            if (value) {
                resolver = NODE_COLOR_BY_ONTOLOGY_RESOLVER_FACTORY.create();
            } else {
                resolver = NODE_BACKGROUND_COLOR_RESOLVER_FACTORY.create();
            }

            visualizationModel.setResolver(Graph.NODE_BACKGROUND_COLOR, resolver);
        }
    });

    resourceModel.getResources().addEventHandler(new ResourceSetChangedEventHandler() {
        @Override
        public void onResourceSetChanged(ResourceSetChangedEvent event) {
            LightweightCollection<Resource> addedResources = event.getAddedResources();
            for (Resource resource : addedResources) {
                if (Concept.isConcept(resource)) {
                    String ontologyAcronym = (String) resource.getValue(Concept.ONTOLOGY_ACRONYM);
                    if (!ontologyToFilterBox.containsKey(ontologyAcronym)) {

                        CheckBox checkBox = new CheckBox("<span style='color: "
                                + BioMixerConceptByOntologyColorResolver.getColor(ontologyAcronym)
                                + "'>&#9609;</span>" + "&nbsp;" + "Show "
                                + resource.getValue(Concept.ONTOLOGY_ACRONYM), true);
                        checkBox.setValue(true);
                        ontologyToFilterBox.put(ontologyAcronym, checkBox);
                        panel.add(checkBox);
                        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                            @Override
                            public void onValueChange(ValueChangeEvent<Boolean> event) {
                                updatePredicate(resourceModel, false, ontologyToFilterBox);

                                // the code below updates the
                                // "Show Mapping Nodes" checkbox
                                // under "Nodes" view part in the
                                // vertical panel
                                // updatePredicate(resourceModel,
                                // mappingNodesCheckbox
                                // .getValue(),
                                // ontologyToFilterBox);
                            }
                        });
                    }
                }
            }
        }
    });

    // next line commented out so the "Show Mapping Nodes" checkbox is not
    // added to the "Nodes" view part in the vertical panel
    // panel.add(mappingNodesCheckbox);
    panel.add(colorByOntologyCheckBox);

    updatePredicate(resourceModel, false, ontologyToFilterBox);

    return new SidePanelSection("Nodes", panel);
}

From source file:org.thechiselgroup.biomixer.client.visualization_component.text.TextVisualization.java

License:Apache License

@Override
public SidePanelSection[] getSidePanelSections() {
    FlowPanel settingsPanel = new FlowPanel();

    final CheckBox oneItemPerRowBox = new CheckBox("One item per row");
    oneItemPerRowBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override//from  ww  w  .  j  a v a  2  s  .c o m
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            setTagCloud(!oneItemPerRowBox.getValue());
        }

    });
    settingsPanel.add(oneItemPerRowBox);
    oneItemPerRowBox.setValue(!tagCloud);

    return new SidePanelSection[] { new SidePanelSection("Settings", settingsPanel), };
}

From source file:org.unitime.timetable.gwt.client.events.EventAdd.java

License:Apache License

public EventAdd(AcademicSessionSelectionBox session, EventPropertiesProvider properties) {
    iSession = session;/*from  w  ww .j  a va 2 s  . co  m*/
    iProperties = properties;
    iForm = new SimpleForm();

    iLookup = new Lookup();
    iLookup.addValueChangeHandler(new ValueChangeHandler<PersonInterface>() {
        @Override
        public void onValueChange(ValueChangeEvent<PersonInterface> event) {
            if (event.getValue() != null) {
                iMainExternalId = event.getValue().getId();
                iMainFName.setText(
                        event.getValue().getFirstName() == null ? "" : event.getValue().getFirstName());
                iMainMName.setText(
                        event.getValue().getMiddleName() == null ? "" : event.getValue().getMiddleName());
                iMainLName.getWidget()
                        .setText(event.getValue().getLastName() == null ? "" : event.getValue().getLastName());
                iMainTitle.setText(
                        event.getValue().getAcademicTitle() == null ? "" : event.getValue().getAcademicTitle());
                iMainPhone.setText(event.getValue().getPhone() == null ? "" : event.getValue().getPhone());
                iMainEmail.getWidget()
                        .setText(event.getValue().getEmail() == null ? "" : event.getValue().getEmail());
                iOriginalContact = new ContactInterface(event.getValue());
                iMainContactChanged.setValue(false, true);
                checkMainContactChanged();
            }
        }
    });
    iAdditionalLookup = new Lookup();
    iAdditionalLookup.addValueChangeHandler(new ValueChangeHandler<PersonInterface>() {
        @Override
        public void onValueChange(ValueChangeEvent<PersonInterface> event) {
            if (event.getValue() != null) {
                final ContactInterface contact = new ContactInterface(event.getValue());
                List<Widget> row = new ArrayList<Widget>();
                row.add(new Label(contact.getName(MESSAGES), false));
                row.add(new Label(contact.hasEmail() ? contact.getEmail() : "", false));
                row.add(new Label(contact.hasPhone() ? contact.getPhone() : "", false));
                Image remove = new Image(RESOURCES.delete());
                remove.addStyleName("remove");
                remove.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        for (int row = 1; row < iContacts.getRowCount(); row++)
                            if (contact.equals(iContacts.getData(row))) {
                                iContacts.removeRow(row);
                                break;
                            }
                        iForm.getRowFormatter().setVisible(iContactRow, iContacts.getRowCount() > 1);
                    }
                });
                row.add(remove);
                int nrInstructors = 0;
                for (int r = 1; r < iContacts.getRowCount(); r++)
                    if (iContacts.getData(r) == null)
                        nrInstructors++;
                int rowNum;
                if (nrInstructors == 0) {
                    rowNum = iContacts.addRow(contact, row);
                } else {
                    rowNum = iContacts.insertRow(iContacts.getRowCount() - nrInstructors);
                    iContacts.setRow(rowNum, contact, row);
                }
                for (int col = 0; col < iContacts.getCellCount(rowNum); col++)
                    iContacts.getCellFormatter().addStyleName(rowNum, col, "additional-contact");
            }
            iForm.getRowFormatter().setVisible(iContactRow, iContacts.getRowCount() > 1);
        }
    });
    iLookup.setOptions("mustHaveExternalId"
            + (iSession.getAcademicSessionId() == null ? "" : ",session=" + iSession.getAcademicSessionId()));
    iAdditionalLookup.setOptions("mustHaveExternalId"
            + (iSession.getAcademicSessionId() == null ? "" : ",session=" + iSession.getAcademicSessionId()));
    iSession.addAcademicSessionChangeHandler(new AcademicSessionProvider.AcademicSessionChangeHandler() {
        @Override
        public void onAcademicSessionChange(AcademicSessionProvider.AcademicSessionChangeEvent event) {
            iLookup.setOptions("mustHaveExternalId,session=" + event.getNewAcademicSessionId());
            iAdditionalLookup.setOptions("mustHaveExternalId,session=" + event.getNewAcademicSessionId());
        }
    });

    iHeader = new UniTimeHeaderPanel(MESSAGES.sectEvent());
    ClickHandler clickCreateOrUpdate = new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            iSavedEvent = null;
            validate(new AsyncCallback<Boolean>() {
                @Override
                public void onFailure(Throwable caught) {
                    UniTimeNotifications.error(MESSAGES.failedValidation(caught.getMessage()), caught);
                }

                @Override
                public void onSuccess(Boolean result) {
                    if (result) {
                        final EventInterface event = getEvent();
                        LoadingWidget.getInstance()
                                .show(event.getId() == null ? MESSAGES.waitCreate(event.getName())
                                        : MESSAGES.waitUpdate(event.getName()));
                        RPC.execute(
                                SaveEventRpcRequest.saveEvent(getEvent(), iSession.getAcademicSessionId(),
                                        getMessage(), isSendEmailConformation()),
                                new AsyncCallback<SaveOrApproveEventRpcResponse>() {

                                    @Override
                                    public void onFailure(Throwable caught) {
                                        LoadingWidget.getInstance().hide();
                                        String message = (event.getId() == null
                                                ? MESSAGES.failedCreate(event.getName(), caught.getMessage())
                                                : MESSAGES.failedUpdate(event.getName(), caught.getMessage()));
                                        iHeader.setErrorMessage(message);
                                        UniTimeNotifications.error(message, caught);
                                    }

                                    @Override
                                    public void onSuccess(SaveOrApproveEventRpcResponse result) {
                                        LoadingWidget.getInstance().hide();
                                        iSavedEvent = result.getEvent();
                                        if (result.hasMessages())
                                            for (MessageInterface m : result.getMessages()) {
                                                if (m.isError())
                                                    UniTimeNotifications.warn(m.getMessage());
                                                else if (m.isWarning())
                                                    UniTimeNotifications.error(m.getMessage());
                                                else
                                                    UniTimeNotifications.info(m.getMessage());
                                            }
                                        hide();
                                    }
                                });
                    }
                }
            });
        }
    };
    iHeader.addButton("create", MESSAGES.buttonCreateEvent(), 100, clickCreateOrUpdate);
    iHeader.addButton("update", MESSAGES.buttonUpdateEvent(), 100, clickCreateOrUpdate);
    iHeader.addButton("delete", MESSAGES.buttonDeleteEvent(), 100, new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            if (!Window.confirm(MESSAGES.confirmDeleteEvent()))
                return;
            final EventInterface event = getEvent();
            if (event.hasMeetings())
                event.getMeetings().clear();
            LoadingWidget.getInstance().show(MESSAGES.waitDelete(event.getName()));
            RPC.execute(SaveEventRpcRequest.saveEvent(event, iSession.getAcademicSessionId(), getMessage(),
                    isSendEmailConformation()), new AsyncCallback<SaveOrApproveEventRpcResponse>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            LoadingWidget.getInstance().hide();
                            iHeader.setErrorMessage(
                                    MESSAGES.failedDelete(event.getName(), caught.getMessage()));
                            UniTimeNotifications
                                    .error(MESSAGES.failedDelete(event.getName(), caught.getMessage()), caught);
                        }

                        @Override
                        public void onSuccess(SaveOrApproveEventRpcResponse result) {
                            LoadingWidget.getInstance().hide();
                            iSavedEvent = result.getEvent();
                            if (result.hasMessages())
                                for (MessageInterface m : result.getMessages()) {
                                    if (m.isError())
                                        UniTimeNotifications.warn(m.getMessage());
                                    else if (m.isWarning())
                                        UniTimeNotifications.error(m.getMessage());
                                    else
                                        UniTimeNotifications.info(m.getMessage());
                                }
                            hide();
                        }
                    });
        }
    });
    iHeader.addButton("cancel", MESSAGES.buttonCancelEvent(), 100, new ClickHandler() {
        @Override
        public void onClick(ClickEvent clickEvent) {
            if (!Window.confirm(MESSAGES.confirmCancelEvent()))
                return;
            final EventInterface event = getEvent();
            if (event.hasMeetings()) {
                for (Iterator<MeetingInterface> i = event.getMeetings().iterator(); i.hasNext();) {
                    MeetingInterface m = i.next();
                    if (m.getId() == null)
                        i.remove();
                    else if (m.isCanCancel())
                        m.setApprovalStatus(ApprovalStatus.Cancelled);
                    else if (m.isCanDelete() && (m.getApprovalStatus() == ApprovalStatus.Pending
                            || m.getApprovalStatus() == ApprovalStatus.Approved))
                        i.remove();
                }
            }
            LoadingWidget.getInstance().show(MESSAGES.waitCancel(event.getName()));
            RPC.execute(SaveEventRpcRequest.saveEvent(event, iSession.getAcademicSessionId(), getMessage(),
                    isSendEmailConformation()), new AsyncCallback<SaveOrApproveEventRpcResponse>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            LoadingWidget.getInstance().hide();
                            iHeader.setErrorMessage(
                                    MESSAGES.failedCancel(event.getName(), caught.getMessage()));
                            UniTimeNotifications
                                    .error(MESSAGES.failedCancel(event.getName(), caught.getMessage()), caught);
                        }

                        @Override
                        public void onSuccess(SaveOrApproveEventRpcResponse result) {
                            LoadingWidget.getInstance().hide();
                            iSavedEvent = result.getEvent();
                            if (result.hasMessages())
                                for (MessageInterface m : result.getMessages()) {
                                    if (m.isError())
                                        UniTimeNotifications.warn(m.getMessage());
                                    else if (m.isWarning())
                                        UniTimeNotifications.error(m.getMessage());
                                    else
                                        UniTimeNotifications.info(m.getMessage());
                                }
                            hide();
                        }
                    });
        }
    });
    iHeader.addButton("back", MESSAGES.buttonBack(), 75, new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            hide();
        }
    });

    iForm.addHeaderRow(iHeader);

    iSessionRow = iForm.addRow(MESSAGES.propAcademicSession(), new Label());

    iName = new UniTimeWidget<TextBox>(new TextBox());
    iName.getWidget().setStyleName("unitime-TextBox");
    iName.getWidget().setMaxLength(100);
    iName.getWidget().setWidth("480px");
    iName.getWidget().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            iName.clearHint();
            iHeader.clearMessage();
        }
    });
    iForm.addRow(MESSAGES.propEventName(), iName);

    iSponsors = new ListBox();
    iForm.addRow(MESSAGES.propSponsor(), iSponsors);

    iEventType = new UniTimeWidget<ListBox>(new ListBox());
    iEventType.getWidget().addItem(EventInterface.EventType.Special.getName(CONSTANTS),
            EventInterface.EventType.Special.name());
    iForm.addRow(MESSAGES.propEventType(), iEventType);

    iLimit = new NumberBox();
    iLimit.setStyleName("unitime-TextBox");
    iLimit.setMaxLength(10);
    iLimit.setWidth("50px");
    iForm.addRow(MESSAGES.propAttendance(), iLimit);

    iCourses = new CourseRelatedObjectsTable(iSession);
    iCourses.addValueChangeHandler(new ValueChangeHandler<List<RelatedObjectInterface>>() {
        @Override
        public void onValueChange(ValueChangeEvent<List<RelatedObjectInterface>> event) {
            checkEnrollments(event.getValue(), iMeetings.getMeetings());
        }
    });

    iReqAttendance = new CheckBox(MESSAGES.checkRequiredAttendance());

    iMainContact = new SimpleForm();
    iMainContact.getElement().getStyle().clearWidth();
    iMainContact.removeStyleName("unitime-NotPrintableBottomLine");

    iLookupButton = new Button(MESSAGES.buttonLookupMainContact());
    iLookupButton.setWidth("75px");
    Character lookupAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.buttonLookupMainContact());
    if (lookupAccessKey != null)
        iLookupButton.setAccessKey(lookupAccessKey);
    iLookupButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (!iLookupButton.isVisible())
                return;
            iLookup.setQuery(
                    (iMainFName.getText() + (iMainMName.getText().isEmpty() ? "" : " " + iMainMName.getText())
                            + " " + iMainLName.getWidget().getText()).trim());
            iLookup.center();
        }
    });
    iLookupButton.setVisible(false);

    iAdditionalLookupButton = new Button(MESSAGES.buttonLookupAdditionalContact());
    iAdditionalLookupButton.setWidth("125px");
    Character additionalLookupAccessKey = UniTimeHeaderPanel
            .guessAccessKey(MESSAGES.buttonLookupAdditionalContact());
    if (additionalLookupAccessKey != null)
        iAdditionalLookupButton.setAccessKey(additionalLookupAccessKey);
    iAdditionalLookupButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (iAdditionalLookupButton.isVisible())
                iAdditionalLookup.center();
        }
    });
    iAdditionalLookupButton.setVisible(false);

    iMainContactResetButton = new Button(MESSAGES.buttonResetMainContact());
    iMainContactResetButton.setWidth("75px");
    Character resetAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.buttonResetMainContact());
    if (resetAccessKey != null)
        iMainContactResetButton.setAccessKey(resetAccessKey);
    iMainContactResetButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (iLookupButton.isVisible()) {
                iOriginalContact = null;
            }
            if (iOriginalContact == null) {
                iMainExternalId = null;
                iMainFName.setText("");
                iMainMName.setText("");
                iMainLName.getWidget().setText("");
                iMainTitle.setText("");
                iMainPhone.setText("");
                iMainEmail.getWidget().setText("");
            } else {
                iMainExternalId = iOriginalContact.getExternalId();
                iMainFName.setText(iOriginalContact.hasFirstName() ? iOriginalContact.getFirstName() : "");
                iMainMName.setText(iOriginalContact.hasMiddleName() ? iOriginalContact.getMiddleName() : "");
                iMainLName.getWidget()
                        .setText(iOriginalContact.hasLastName() ? iOriginalContact.getLastName() : "");
                iMainTitle.setText(
                        iOriginalContact.hasAcademicTitle() ? iOriginalContact.getAcademicTitle() : "");
                iMainPhone.setText(iOriginalContact.hasPhone() ? iOriginalContact.getPhone() : "");
                iMainEmail.getWidget().setText(iOriginalContact.hasEmail() ? iOriginalContact.getEmail() : "");
            }
            iMainContactChanged.setValue(false, true);
            checkMainContactChanged();
        }
    });
    iMainContactResetButton.setVisible(false);

    iMainFName = new TextBox();
    iMainFName.setStyleName("unitime-TextBox");
    iMainFName.setMaxLength(100);
    iMainFName.setWidth("285px");
    iMainContact.addRow(MESSAGES.propFirstName(), iMainFName);
    iMainContact.setWidget(0, 2, iLookupButton);
    iMainContact.setWidget(0, 3, iMainContactResetButton);

    iMainMName = new TextBox();
    iMainMName.setStyleName("unitime-TextBox");
    iMainMName.setMaxLength(100);
    iMainMName.setWidth("285px");
    iMainContact.addRow(MESSAGES.propMiddleName(), iMainMName);

    iMainLName = new UniTimeWidget<TextBox>(new TextBox());
    iMainLName.getWidget().setStyleName("unitime-TextBox");
    iMainLName.getWidget().setMaxLength(100);
    iMainLName.getWidget().setWidth("285px");
    iMainLName.getWidget().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            iMainLName.clearHint();
            iHeader.clearMessage();
        }
    });
    iMainContact.addRow(MESSAGES.propLastName(), iMainLName);

    iMainTitle = new TextBox();
    iMainTitle.setStyleName("unitime-TextBox");
    iMainTitle.setMaxLength(50);
    iMainTitle.setWidth("285px");
    iAcademicTitleRow = iMainContact.addRow(MESSAGES.propAcademicTitle(), iMainTitle);

    iMainEmail = new UniTimeWidget<TextBox>(new TextBox());
    iMainEmail.getWidget().setStyleName("unitime-TextBox");
    iMainEmail.getWidget().setMaxLength(200);
    iMainEmail.getWidget().setWidth("285px");
    iMainEmail.getWidget().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            iMainEmail.clearHint();
            iHeader.clearMessage();
        }
    });
    iMainContact.addRow(MESSAGES.propEmail(), iMainEmail);

    iMainPhone = new TextBox();
    iMainPhone.setStyleName("unitime-TextBox");
    iMainPhone.setMaxLength(35);
    iMainPhone.setWidth("285px");
    iMainContact.addRow(MESSAGES.propPhone(), iMainPhone);
    iMainContact.setWidget(iMainContact.getRowCount() - 1, 2, iAdditionalLookupButton);
    iMainContact.getFlexCellFormatter().setColSpan(iMainContact.getRowCount() - 1, 2, 2);

    ValueChangeHandler<String> checkMainContactHandler = new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            checkMainContactChanged();
        }
    };
    iMainFName.addValueChangeHandler(checkMainContactHandler);
    iMainMName.addValueChangeHandler(checkMainContactHandler);
    iMainLName.getWidget().addValueChangeHandler(checkMainContactHandler);
    iMainTitle.addValueChangeHandler(checkMainContactHandler);
    iMainPhone.addValueChangeHandler(checkMainContactHandler);
    iMainEmail.getWidget().addValueChangeHandler(checkMainContactHandler);

    iForm.addRow(MESSAGES.propMainContact(), iMainContact);

    iMainContactChanged = new CheckBox(MESSAGES.checkYourContactChange());
    iMainContactChangedRow = iForm.addRow("", iMainContactChanged);
    iForm.getRowFormatter().setVisible(iMainContactChangedRow, false);
    iForm.getCellFormatter().setStyleName(iMainContactChangedRow, 1, "unitime-CheckNotConfirmed");

    iMainContactChanged.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            checkMainContactChanged();
            iHeader.clearMessage();
        }
    });

    iContacts = new UniTimeTable<ContactInterface>();
    iContacts.setStyleName("unitime-EventContacts");

    List<Widget> contactHeader = new ArrayList<Widget>();
    contactHeader.add(new UniTimeTableHeader(MESSAGES.colNamePerson()));
    contactHeader.add(new UniTimeTableHeader(MESSAGES.colEmail()));
    contactHeader.add(new UniTimeTableHeader(MESSAGES.colPhone()));
    contactHeader.add(new UniTimeTableHeader("&nbsp;"));
    iContacts.addRow(null, contactHeader);

    iContactRow = iForm.addRow(MESSAGES.propAdditionalContacts(), iContacts);
    iForm.getRowFormatter().setVisible(iContactRow, false);

    iEmails = new TextArea();
    iEmails.setStyleName("unitime-TextArea");
    iEmails.setVisibleLines(3);
    iEmails.setCharacterWidth(80);
    UniTimeWidget<TextArea> emailsWithHint = new UniTimeWidget<TextArea>(iEmails);
    emailsWithHint.setHint(MESSAGES.hintAdditionalEmails());
    iForm.addRow(MESSAGES.propAdditionalEmails(), emailsWithHint);

    iStandardNotes = new ListBox();
    iStandardNotes.setVisibleItemCount(10);
    iStandardNotes.setWidth("600px");
    iStandardNotes.addDoubleClickHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            String text = iNotes.getText();
            if (!text.isEmpty() && !text.endsWith("\n"))
                text += "\n";
            text += iStandardNotes.getValue(iStandardNotes.getSelectedIndex());
            iNotes.setText(text);
            iStandardNotesBox.hide();
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    iNotes.setFocus(true);
                }
            });
        }
    });
    iStandardNotes.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                String text = iNotes.getText();
                if (!text.isEmpty() && !text.endsWith("\n"))
                    text += "\n";
                text += iStandardNotes.getValue(iStandardNotes.getSelectedIndex());
                iNotes.setText(text);
                event.preventDefault();
                event.stopPropagation();
                iStandardNotesBox.hide();
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    @Override
                    public void execute() {
                        iNotes.setFocus(true);
                    }
                });
            }
        }
    });
    UniTimeWidget<ListBox> standardNotesWithHint = new UniTimeWidget<ListBox>(iStandardNotes);
    standardNotesWithHint.setHint(MESSAGES.hintStandardNoteDoubleClickToSelect());
    SimpleForm standardNotesForm = new SimpleForm();
    standardNotesForm.addRow(standardNotesWithHint);
    final UniTimeHeaderPanel standardNotesFooter = new UniTimeHeaderPanel();
    standardNotesForm.addRow(standardNotesFooter);
    iStandardNotesBox = new UniTimeDialogBox(true, false);
    iStandardNotesBox.setText(MESSAGES.dialogStandardNotes());
    iStandardNotesBox.setWidget(standardNotesForm);
    standardNotesFooter.addButton("select", MESSAGES.buttonSelect(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (iStandardNotes.getSelectedIndex() >= 0) {
                String text = iNotes.getText();
                if (!text.isEmpty() && !text.endsWith("\n"))
                    text += "\n";
                text += iStandardNotes.getValue(iStandardNotes.getSelectedIndex());
                iNotes.setText(text);
            }
            iStandardNotesBox.hide();
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    iNotes.setFocus(true);
                }
            });
        }
    });
    standardNotesFooter.addButton("cancel", MESSAGES.buttonCancel(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            iStandardNotesBox.hide();
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    iNotes.setFocus(true);
                }
            });
        }
    });
    standardNotesFooter.setEnabled("select", false);
    iStandardNotes.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            standardNotesFooter.setEnabled("select", iStandardNotes.getSelectedIndex() >= 0);
        }
    });

    iNotes = new TextArea();
    iNotes.setStyleName("unitime-TextArea");
    iNotes.setVisibleLines(5);
    iNotes.setCharacterWidth(80);
    VerticalPanel notesPanel = new VerticalPanel();
    notesPanel.add(iNotes);
    notesPanel.setSpacing(0);
    iStandardNotesButton = new Button(MESSAGES.buttonStandardNotes(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (iStandardNotes.getItemCount() > 0) {
                iStandardNotesBox.center();
                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                    @Override
                    public void execute() {
                        iStandardNotes.setFocus(true);
                    }
                });
            }
        }
    });
    Character standardNotesButtonAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.buttonStandardNotes());
    if (standardNotesButtonAccessKey != null)
        iStandardNotesButton.setAccessKey(standardNotesButtonAccessKey);
    iStandardNotesButton.setVisible(false);
    iStandardNotesButton.getElement().getStyle().setMarginTop(2, Unit.PX);
    notesPanel.add(iStandardNotesButton);
    notesPanel.setCellHorizontalAlignment(iStandardNotesButton, HasHorizontalAlignment.ALIGN_RIGHT);

    int row = iForm.addRow(MESSAGES.propAdditionalInformation(), notesPanel);
    Roles.getTextboxRole().setAriaLabelledbyProperty(iNotes.getElement(),
            Id.of(iForm.getWidget(row, 0).getElement()));

    iFileUpload = new UniTimeFileUpload();
    iForm.addRow(MESSAGES.propAttachment(), iFileUpload);

    iExpirationDate = new SingleDateSelector();
    iExpirationDate.setFirstDate(iExpirationDate.today());
    iForm.addRow(MESSAGES.propExpirationDate(), iExpirationDate);

    iCoursesForm = new SimpleForm();
    iCoursesForm.addHeaderRow(MESSAGES.sectRelatedCourses());
    iCoursesForm.removeStyleName("unitime-NotPrintableBottomLine");
    iCoursesForm.addRow(iCourses);
    iCoursesForm.addRow(iReqAttendance);
    iForm.addRow(iCoursesForm);

    iEventType.getWidget().addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            EventType type = getEventType();
            iName.setReadOnly(
                    type == EventType.Class || type == EventType.MidtermExam || type == EventType.FinalExam);
            iEvent.setType(type);
            iCoursesForm.setVisible(type == EventType.Course);
            iForm.getRowFormatter().setVisible(iForm.getRow(MESSAGES.propAttendance()),
                    type == EventType.Special);
            iForm.getRowFormatter().setVisible(iForm.getRow(MESSAGES.propSponsor()),
                    type != EventType.Unavailabile && type != EventType.Class && type != EventType.MidtermExam
                            && type != EventType.FinalExam && iSponsors.getItemCount() > 0);
            iForm.getRowFormatter().setVisible(iForm.getRow(MESSAGES.propExpirationDate()),
                    getProperties() != null
                            && (getProperties().isCanSetExpirationDate() || iExpirationDate.getValue() != null)
                            && type != EventType.Unavailabile && type != EventType.Class
                            && type != EventType.MidtermExam && type != EventType.FinalExam);
            if (iMeetings.getRowCount() > 1) {
                LoadingWidget.getInstance().show(MESSAGES.waitCheckingRoomAvailability());
                RPC.execute(
                        EventRoomAvailabilityRpcRequest.checkAvailability(iMeetings.getMeetings(), getEventId(),
                                getEventType(), iSession.getAcademicSessionId()),
                        new AsyncCallback<EventRoomAvailabilityRpcResponse>() {
                            @Override
                            public void onFailure(Throwable caught) {
                                LoadingWidget.getInstance().hide();
                                UniTimeNotifications.error(MESSAGES.failedRoomAvailability(caught.getMessage()),
                                        caught);
                            }

                            @Override
                            public void onSuccess(EventRoomAvailabilityRpcResponse result) {
                                LoadingWidget.getInstance().hide();
                                iMeetings.setMeetings(iEvent, result.getMeetings());
                                checkEnrollments(iCourses.getValue(), iMeetings.getMeetings());
                                showCreateButtonIfApplicable();
                            }
                        });
            }
        }
    });

    iEventAddMeetings = new AddMeetingsDialog(session, iProperties,
            new AsyncCallback<List<MeetingInterface>>() {
                @Override
                public void onFailure(Throwable caught) {
                    UniTimeNotifications.error(MESSAGES.failedAddMeetings(caught.getMessage()), caught);
                }

                @Override
                public void onSuccess(List<MeetingInterface> result) {
                    LoadingWidget.getInstance().show(MESSAGES.waitCheckingRoomAvailability());
                    RPC.execute(
                            EventRoomAvailabilityRpcRequest.checkAvailability(result, getEventId(),
                                    getEventType(), iSession.getAcademicSessionId()),
                            new AsyncCallback<EventRoomAvailabilityRpcResponse>() {
                                @Override
                                public void onFailure(Throwable caught) {
                                    LoadingWidget.getInstance().hide();
                                    UniTimeNotifications.error(
                                            MESSAGES.failedRoomAvailability(caught.getMessage()), caught);
                                }

                                @Override
                                public void onSuccess(EventRoomAvailabilityRpcResponse result) {
                                    LoadingWidget.getInstance().hide();
                                    addMeetings(result.getMeetings());
                                    iEventAddMeetings.reset(
                                            iProperties == null ? null : iProperties.getRoomFilter(),
                                            iProperties == null ? null : iProperties.getSelectedDates(),
                                            iProperties == null ? null : iProperties.getSelectedTime());
                                }
                            });
                }
            });
    iEventModifyMeetings = new AddMeetingsDialog(session, iProperties,
            new AsyncCallback<List<MeetingInterface>>() {
                @Override
                public void onFailure(Throwable caught) {
                    UniTimeNotifications.error(MESSAGES.failedChangeMeetings(caught.getMessage()), caught);
                }

                @Override
                public void onSuccess(List<MeetingInterface> result) {
                    final List<MeetingInterface> meetings = iMeetings.getMeetings();
                    if (!iEventType.isReadOnly())
                        iEvent.setType(getEventType());
                    RPC.execute(
                            EventRoomAvailabilityRpcRequest.checkAvailability(result, getEventId(),
                                    getEventType(), iSession.getAcademicSessionId()),
                            new AsyncCallback<EventRoomAvailabilityRpcResponse>() {
                                @Override
                                public void onFailure(Throwable caught) {
                                    LoadingWidget.getInstance().hide();
                                    UniTimeNotifications.error(
                                            MESSAGES.failedRoomAvailability(caught.getMessage()), caught);
                                }

                                @Override
                                public void onSuccess(EventRoomAvailabilityRpcResponse result) {
                                    LoadingWidget.getInstance().hide();
                                    List<MeetingInterface> added = new ArrayList<EventInterface.MeetingInterface>(
                                            result.getMeetings());
                                    current: for (Iterator<MeetingInterface> i = meetings.iterator(); i
                                            .hasNext();) {
                                        MeetingInterface meeting = i.next();
                                        if (meeting.getApprovalStatus() != ApprovalStatus.Pending
                                                && meeting.getApprovalStatus() != ApprovalStatus.Approved)
                                            continue;
                                        if (!iSelection.contains(meeting))
                                            continue;
                                        for (Iterator<MeetingInterface> j = added.iterator(); j.hasNext();) {
                                            MeetingInterface m = j.next();
                                            if (m.getDayOfYear() == meeting.getDayOfYear()
                                                    && EventInterface.equals(meeting.getLocation(),
                                                            m.getLocation())
                                                    && meeting.getStartSlot() == m.getStartSlot()
                                                    && meeting.getEndSlot() == m.getEndSlot()) {
                                                j.remove();
                                                continue current;
                                            }
                                        }
                                        if (meeting.getId() == null) {
                                            i.remove();
                                        } else if (meeting.getApprovalStatus() == ApprovalStatus.Cancelled
                                                || meeting.getApprovalStatus() == ApprovalStatus.Deleted) {
                                            // already cancelled or deleted
                                        } else if (meeting.isCanDelete()) {
                                            meeting.setApprovalStatus(ApprovalStatus.Deleted);
                                            meeting.setCanApprove(false);
                                            meeting.setCanCancel(false);
                                            meeting.setCanInquire(false);
                                            meeting.setCanEdit(false);
                                            meeting.setCanDelete(false);
                                        } else if (meeting.isCanCancel()) {
                                            meeting.setApprovalStatus(ApprovalStatus.Cancelled);
                                            meeting.setCanApprove(false);
                                            meeting.setCanCancel(false);
                                            meeting.setCanInquire(false);
                                            meeting.setCanEdit(false);
                                            meeting.setCanDelete(false);
                                        }
                                    }
                                    added: for (MeetingInterface meeting : added) {
                                        if (meeting.getApprovalStatus() != ApprovalStatus.Pending
                                                && meeting.getApprovalStatus() != ApprovalStatus.Approved)
                                            continue;
                                        for (MeetingInterface existing : meetings) {
                                            if (existing.getApprovalStatus() != ApprovalStatus.Pending
                                                    && existing.getApprovalStatus() != ApprovalStatus.Approved)
                                                continue;
                                            if (existing.inConflict(meeting)) {
                                                UniTimeNotifications.warn(MESSAGES.warnNewMeetingOverlaps(
                                                        meeting.toString(), existing.toString()));
                                                continue added;
                                            }
                                        }
                                        meetings.add(meeting);
                                    }
                                    Collections.sort(meetings);

                                    boolean hasSelection = false;
                                    for (int row = 1; row < iMeetings.getRowCount(); row++) {
                                        Widget w = iMeetings.getWidget(row, 0);
                                        if (w != null && w instanceof CheckBox) {
                                            CheckBox ch = (CheckBox) w;
                                            if (ch.getValue()) {
                                                hasSelection = true;
                                                break;
                                            }
                                        }
                                    }

                                    iMeetings.setMeetings(iEvent, meetings);
                                    showCreateButtonIfApplicable();
                                    ValueChangeEvent.fire(iMeetings, iMeetings.getValue());

                                    if (hasSelection)
                                        rows: for (int row = 1; row < iMeetings.getRowCount(); row++) {
                                            Widget w = iMeetings.getWidget(row, 0);
                                            if (w != null && w instanceof CheckBox) {
                                                CheckBox ch = (CheckBox) w;
                                                MeetingInterface meeting = iMeetings.getData(row).getMeeting();
                                                for (MeetingInterface m : result.getMeetings()) {
                                                    if (m.getDayOfYear() == meeting.getDayOfYear()
                                                            && EventInterface.equals(meeting.getLocation(),
                                                                    m.getLocation())
                                                            && meeting.getStartSlot() == m.getStartSlot()
                                                            && meeting.getEndSlot() == m.getEndSlot()) {
                                                        ch.setValue(true);
                                                        continue rows;
                                                    }
                                                }
                                            }
                                        }
                                }
                            });
                }
            });
    iEventModifyMeetings.setText(MESSAGES.dialogModifyMeetings());

    iMeetingsHeader = new UniTimeHeaderPanel(MESSAGES.sectMeetings());
    iMeetingsHeader.addButton("add", MESSAGES.buttonAddMeetings(), 100, new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            iEventAddMeetings.showDialog(getEventId(), getConflicts());
        }
    });
    iMeetingsHeader.addButton("operations", MESSAGES.buttonMoreOperations(), 75, new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            final PopupPanel popup = new PopupPanel(true);
            iMeetings.getHeader(0).setMenu(popup);
            popup.showRelativeTo((UIObject) event.getSource());
            ((MenuBar) popup.getWidget()).focus();
        }
    });
    iForm.addHeaderRow(iMeetingsHeader);

    iMeetings = new EventMeetingTable(EventMeetingTable.Mode.MeetingsOfAnEvent, true, iProperties);
    iMeetings.setEditable(true);
    iMeetings.setOperation(EventMeetingTable.OperationType.AddMeetings, this);
    iMeetings.setOperation(EventMeetingTable.OperationType.Delete, this);
    iMeetings.setOperation(EventMeetingTable.OperationType.Cancel, this);
    iMeetings.setOperation(EventMeetingTable.OperationType.Modify, this);
    iMeetings.addValueChangeHandler(new ValueChangeHandler<List<EventMeetingRow>>() {
        @Override
        public void onValueChange(ValueChangeEvent<List<EventMeetingRow>> event) {
            checkEnrollments(iCourses.getValue(), iMeetings.getMeetings());
            showCreateButtonIfApplicable();
        }
    });

    iForm.addRow(iMeetings);

    iShowDeleted = new CheckBox("<i>" + MESSAGES.showDeletedMeetings() + "</i>", true);
    iForm.addRow(iShowDeleted);
    iForm.getCellFormatter().setHorizontalAlignment(iForm.getRowCount() - 1, 0,
            HasHorizontalAlignment.ALIGN_RIGHT);
    iShowDeleted.setValue(EventCookie.getInstance().isShowDeletedMeetings());
    iShowDeleted.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            iMeetings.setMeetings(iEvent, iMeetings.getMeetings());
            EventCookie.getInstance().setShowDeletedMeetings(event.getValue());
            if (event.getValue())
                iMeetings.removeStyleName("unitime-EventMeetingsHideDeleted");
            else
                iMeetings.addStyleName("unitime-EventMeetingsHideDeleted");
        }
    });
    if (!iShowDeleted.getValue())
        iMeetings.addStyleName("unitime-EventMeetingsHideDeleted");

    iEnrollments = new EnrollmentTable(false, true);
    iEnrollments.getTable().setStyleName("unitime-Enrollments");
    iEnrollmentHeader = new UniTimeHeaderPanel(MESSAGES.sectEnrollments());
    iEnrollmentRow = iForm.addHeaderRow(iEnrollmentHeader);
    iForm.addRow(iEnrollments.getTable());
    iForm.getRowFormatter().setVisible(iEnrollmentRow, false);
    iForm.getRowFormatter().setVisible(iEnrollmentRow + 1, false);

    iFooter = iHeader.clonePanel("");

    iEmailConfirmationHeader = new CheckBox(MESSAGES.checkSendEmailConfirmation(), true);
    iEmailConfirmationHeader.addStyleName("toggle");
    iHeader.getPanel().insert(iEmailConfirmationHeader, 4);
    iHeader.getPanel().setCellVerticalAlignment(iEmailConfirmationHeader, HasVerticalAlignment.ALIGN_MIDDLE);

    iEmailConfirmationFooter = new CheckBox(MESSAGES.checkSendEmailConfirmation(), true);
    iEmailConfirmationFooter.addStyleName("toggle");
    iFooter.getPanel().insert(iEmailConfirmationFooter, 4);
    iFooter.getPanel().setCellVerticalAlignment(iEmailConfirmationFooter, HasVerticalAlignment.ALIGN_MIDDLE);

    iEmailConfirmationHeader.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            iEmailConfirmationFooter.setValue(event.getValue(), false);
        }
    });
    iEmailConfirmationFooter.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            iEmailConfirmationHeader.setValue(event.getValue(), false);
        }
    });

    iForm.addNotPrintableBottomRow(iFooter);

    iMeetings.addMouseClickListener(new UniTimeTable.MouseClickListener<EventMeetingRow>() {
        @Override
        public void onMouseClick(UniTimeTable.TableEvent<EventMeetingRow> event) {
            EventMeetingRow row = event.getData();
            if (row == null)
                return;
            if (row.getParent() != null)
                row = row.getParent();
            MeetingInterface meeting = row.getMeeting();
            if (meeting == null)
                return;
            if (iMeetings.isSelectable(row)
                    && (meeting.getId() == null || meeting.isCanCancel() || meeting.isCanDelete())) {
                List<EventMeetingRow> selection = new ArrayList<EventMeetingRow>();
                selection.add(row);
                execute(iMeetings, OperationType.Modify, selection);
            } else if (!row.getMeeting().isPast()
                    && (row.getMeeting().getApprovalStatus() == ApprovalStatus.Cancelled
                            || row.getMeeting().getApprovalStatus() == ApprovalStatus.Deleted)) {
                List<EventMeetingRow> selection = new ArrayList<EventMeetingRow>();
                selection.add(row);
                execute(iMeetings, OperationType.Modify, selection);
            }
        }
    });

    initWidget(iForm);
}

From source file:org.unitime.timetable.gwt.client.events.EventMeetingTable.java

License:Apache License

public EventMeetingTable(Mode mode, boolean selectable, EventPropertiesProvider properties) {
    setStyleName("unitime-EventMeetings");

    iMode = mode;/*from www .j ava  2  s  .  c  om*/
    iSelectable = selectable;
    iPropertiesProvider = properties;

    if (getRowCount() > 0)
        clearTable();

    List<UniTimeTableHeader> header = new ArrayList<UniTimeTableHeader>();

    UniTimeTableHeader hTimes = new UniTimeTableHeader("&otimes;", HasHorizontalAlignment.ALIGN_CENTER);
    header.add(hTimes);
    hTimes.addOperation(new Operation() {
        @Override
        public void execute() {
            for (int row = 1; row < getRowCount(); row++) {
                Widget w = getWidget(row, 0);
                if (w != null && w instanceof CheckBox) {
                    CheckBox ch = (CheckBox) w;
                    ch.setValue(true);
                }
            }
        }

        @Override
        public boolean isApplicable() {
            for (int row = 1; row < getRowCount(); row++) {
                Widget w = getWidget(row, 0);
                if (w != null && w instanceof CheckBox) {
                    CheckBox ch = (CheckBox) w;
                    if (!ch.getValue())
                        return true;
                }
            }
            return false;
        }

        @Override
        public boolean hasSeparator() {
            return false;
        }

        @Override
        public String getName() {
            return MESSAGES.opSelectAll();
        }
    });
    hTimes.addOperation(new Operation() {
        @Override
        public void execute() {
            for (int row = 1; row < getRowCount(); row++) {
                Widget w = getWidget(row, 0);
                if (w != null && w instanceof CheckBox) {
                    CheckBox ch = (CheckBox) w;
                    ch.setValue(getData(row).inConflict());
                }
            }
        }

        @Override
        public boolean isApplicable() {
            for (int row = 1; row < getRowCount(); row++) {
                Widget w = getWidget(row, 0);
                if (w != null && w instanceof CheckBox)
                    if (getData(row).inConflict())
                        return true;
            }
            return false;
        }

        @Override
        public boolean hasSeparator() {
            return false;
        }

        @Override
        public String getName() {
            return MESSAGES.opSelectAllConflicting();
        }
    });
    hTimes.addOperation(new Operation() {
        @Override
        public void execute() {
            for (int row = 1; row < getRowCount(); row++) {
                Widget w = getWidget(row, 0);
                if (w != null && w instanceof CheckBox) {
                    CheckBox ch = (CheckBox) w;
                    ch.setValue(false);
                }
            }
        }

        @Override
        public boolean isApplicable() {
            for (int row = 1; row < getRowCount(); row++) {
                Widget w = getWidget(row, 0);
                if (w != null && w instanceof CheckBox) {
                    CheckBox ch = (CheckBox) w;
                    if (ch.getValue())
                        return true;
                }
            }
            return false;
        }

        @Override
        public boolean hasSeparator() {
            return false;
        }

        @Override
        public String getName() {
            return MESSAGES.opClearSelection();
        }
    });
    hTimes.addOperation(new Operation() {
        @Override
        public void execute() {
            getOperation(OperationType.AddMeetings).execute(EventMeetingTable.this, OperationType.AddMeetings,
                    null);
        }

        @Override
        public boolean isApplicable() {
            return hasOperation(OperationType.AddMeetings);
        }

        @Override
        public boolean hasSeparator() {
            return true;
        }

        @Override
        public String getName() {
            return MESSAGES.opAddMeetings();
        }
    });
    hTimes.addOperation(new EventMeetingOperation() {
        @Override
        public boolean hasSeparator() {
            return false;
        }

        @Override
        public String getName() {
            return (hasSelection() ? MESSAGES.opDeleteSelectedMeetings() : MESSAGES.opDeleteNewMeetings());
        }

        @Override
        public boolean isApplicable(EventMeetingRow row) {
            return isEditable() && row.isCanDelete();
        }

        @Override
        public void execute(int row, EventMeetingRow event) {
            while (row + 1 < getRowCount() && getData(row + 1).hasParent())
                removeRow(row + 1);
            if (getData(row).getMeeting().getId() == null)
                removeRow(row);
            else {
                MeetingInterface meeting = getData(row).getMeeting();
                meeting.setApprovalStatus(ApprovalStatus.Deleted);
                meeting.setCanApprove(false);
                meeting.setCanCancel(false);
                meeting.setCanInquire(false);
                meeting.setCanEdit(false);
                meeting.setCanDelete(false);
                getRowFormatter().addStyleName(row, "deleted-row");
                setWidget(row, 0, new HTML("&nbsp;"));
                HTML approval = (HTML) getWidget(row, getHeader(MESSAGES.colApproval()).getColumn());
                approval.setStyleName("deleted-meeting");
                approval.setText(MESSAGES.approvalDeleted());
                ValueChangeEvent.fire(EventMeetingTable.this, getValue());
            }
        }

        @Override
        public void execute() {
            super.execute();
            if (hasOperation(OperationType.Delete))
                getOperation(OperationType.Delete).execute(EventMeetingTable.this, OperationType.Delete, null);
        }
    });
    hTimes.addOperation(new EventMeetingOperation() {
        @Override
        public boolean hasSeparator() {
            return true;
        }

        @Override
        public boolean allMustMatch(boolean hasSelection) {
            return false;
        }

        @Override
        public String getName() {
            return (hasSelection() ? MESSAGES.opInquireSelectedMeetings() : MESSAGES.opInquireAllMeetings());
        }

        @Override
        public boolean isApplicable(EventMeetingRow row) {
            return hasOperation(OperationType.Inquire) && row.isCanInquire();
        }

        @Override
        public void execute(int row, EventMeetingRow event) {
        }

        @Override
        public void execute() {
            getOperation(OperationType.Inquire).execute(EventMeetingTable.this, OperationType.Inquire, data());
        }

        @Override
        public boolean allowNoSelection() {
            return getMode().hasFlag(ModeFlag.AllowApproveAll);
        }
    });
    hTimes.addOperation(new EventMeetingOperation() {
        @Override
        public boolean hasSeparator() {
            return false;
        }

        @Override
        public String getName() {
            return (hasSelection() ? MESSAGES.opApproveSelectedMeetings() : MESSAGES.opApproveAllMeetings());
        }

        @Override
        public boolean isApplicable(EventMeetingRow row) {
            return hasOperation(OperationType.Approve) && row.isCanApprove();
        }

        @Override
        public void execute(int row, EventMeetingRow event) {
        }

        @Override
        public void execute() {
            getOperation(OperationType.Approve).execute(EventMeetingTable.this, OperationType.Approve, data());
        }

        @Override
        public boolean allowNoSelection() {
            return getMode().hasFlag(ModeFlag.AllowApproveAll);
        }
    });
    hTimes.addOperation(new EventMeetingOperation() {
        @Override
        public boolean hasSeparator() {
            return false;
        }

        @Override
        public String getName() {
            if (hasOperation(OperationType.Delete))
                return (hasSelection() ? MESSAGES.opCancelSelectedMeetingsNoPopup()
                        : MESSAGES.opCancelAllMeetingsNoPopup());
            else
                return (hasSelection() ? MESSAGES.opCancelSelectedMeetings() : MESSAGES.opCancelAllMeetings());
        }

        @Override
        public boolean isApplicable(EventMeetingRow row) {
            return (hasOperation(OperationType.Cancel) && row.isCanCancel())
                    || (isEditable() && row.isCanCancel());
        }

        @Override
        public void execute(int row, EventMeetingRow event) {
            if (isEditable()) {
                while (row + 1 < getRowCount() && getData(row + 1).hasParent())
                    removeRow(row + 1);
                if (getData(row).getMeeting().getId() == null)
                    removeRow(row);
                else {
                    getData(row).getMeeting().setApprovalStatus(ApprovalStatus.Cancelled);
                    getRowFormatter().addStyleName(row, "cancelled-row");
                    setWidget(row, 0, new HTML("&nbsp;"));
                    HTML approval = (HTML) getWidget(row, getHeader(MESSAGES.colApproval()).getColumn());
                    approval.setStyleName("cancelled-meeting");
                    approval.setText(MESSAGES.approvalCancelled());
                    ValueChangeEvent.fire(EventMeetingTable.this, getValue());
                }
            }
        }

        @Override
        public void execute() {
            super.execute();
            if (hasOperation(OperationType.Cancel))
                getOperation(OperationType.Cancel).execute(EventMeetingTable.this, OperationType.Cancel,
                        data());
        }

        @Override
        public boolean allowNoSelection() {
            return getMode().hasFlag(ModeFlag.AllowApproveAll);
        }
    });
    hTimes.addOperation(new EventMeetingOperation() {
        @Override
        public boolean hasSeparator() {
            return false;
        }

        @Override
        public String getName() {
            return (hasSelection() ? MESSAGES.opRejectSelectedMeetings() : MESSAGES.opRejectAllMeetings());
        }

        @Override
        public boolean isApplicable(EventMeetingRow row) {
            return hasOperation(OperationType.Reject) && row.isCanApprove();
        }

        @Override
        public void execute(int row, EventMeetingRow event) {
        }

        @Override
        public void execute() {
            getOperation(OperationType.Reject).execute(EventMeetingTable.this, OperationType.Reject, data());
        }

        @Override
        public boolean allowNoSelection() {
            return getMode().hasFlag(ModeFlag.AllowApproveAll);
        }
    });
    hTimes.addOperation(new EventMeetingOperation() {
        @Override
        public void execute() {
            getOperation(OperationType.Modify).execute(EventMeetingTable.this, OperationType.Modify, data());
        }

        @Override
        public String getName() {
            return MESSAGES.opModifyMeetings();
        }

        @Override
        public boolean isApplicable() {
            Integer start = null, end = null;
            boolean hasSelection = hasSelection();
            if (hasSelection) {
                for (int row = 1; row < getRowCount(); row++) {
                    Widget w = getWidget(row, 0);
                    if (w != null && w instanceof CheckBox) {
                        CheckBox ch = (CheckBox) w;
                        if (ch.getValue()) {
                            EventMeetingRow e = getData(row);
                            if (!isApplicable(e))
                                return false;
                            if (start == null) {
                                start = e.getMeeting().getStartSlot();
                                end = e.getMeeting().getEndSlot();
                            } else if (start != e.getMeeting().getStartSlot()
                                    || end != e.getMeeting().getEndSlot())
                                return false;
                        }
                    }
                }
                return true;
            } else if (allowNoSelection()) {
                boolean canSelect = false;
                for (int row = 1; row < getRowCount(); row++) {
                    Widget w = getWidget(row, 0);
                    if (w != null && w instanceof CheckBox) {
                        EventMeetingRow e = getData(row);
                        if (!isApplicable(e))
                            return false;
                        if (start == null) {
                            start = e.getMeeting().getStartSlot();
                            end = e.getMeeting().getEndSlot();
                        } else if (start != e.getMeeting().getStartSlot() || end != e.getMeeting().getEndSlot())
                            return false;
                        canSelect = true;
                    }
                }
                return canSelect;
            } else {
                return false;
            }
        }

        @Override
        public boolean allMustMatch(boolean hasSelection) {
            return true;
        }

        @Override
        public boolean isApplicable(EventMeetingRow data) {
            return isEditable() && hasOperation(OperationType.Modify) && data.getMeeting() != null
                    && (data.getMeeting().getId() == null || data.getMeeting().isCanDelete()
                            || data.getMeeting().isCanCancel());
        }

        @Override
        public void execute(int row, EventMeetingRow data) {
        }
    });
    hTimes.addOperation(new EventMeetingOperation() {
        @Override
        public void execute() {
            Integer so = null, eo = null;
            boolean soSame = true, eoSame = true;
            for (EventMeetingRow r : data()) {
                MeetingInterface m = r.getMeeting();
                if (so == null)
                    so = m.getStartOffset();
                else if (m.getStartOffset() != so)
                    soSame = false;
                if (eo == null)
                    eo = -m.getEndOffset();
                else if (-m.getEndOffset() != eo)
                    eoSame = false;
            }
            final UniTimeDialogBox dialog = new UniTimeDialogBox(true, false);
            SimpleForm simple = new SimpleForm();
            simple.removeStyleName("unitime-NotPrintableBottomLine");
            final NumberBox setupTime = new NumberBox();
            if (soSame && so != null)
                setupTime.setValue(so);
            simple.addRow(MESSAGES.propSetupTime(), setupTime);
            final NumberBox teardownTime = new NumberBox();
            if (eoSame && eo != null)
                teardownTime.setValue(eo);
            simple.addRow(MESSAGES.propTeardownTime(), teardownTime);
            UniTimeHeaderPanel footer = new UniTimeHeaderPanel();
            footer.addButton("ok", MESSAGES.buttonOk(), 75, new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    int colSetup = getHeader(MESSAGES.colSetupTimeShort()).getColumn();
                    int colTear = getHeader(MESSAGES.colTeardownTimeShort()).getColumn();
                    int colPubl = getHeader(MESSAGES.colPublishedTime()).getColumn();
                    for (Integer row : rows()) {
                        MeetingInterface meeting = getData(row).getMeeting();
                        if (setupTime.toInteger() != null)
                            meeting.setStartOffset(setupTime.toInteger());
                        if (teardownTime.toInteger() != null)
                            meeting.setEndOffset(-teardownTime.toInteger());
                        ((NumberCell) getWidget(row, colSetup))
                                .setText(String.valueOf(meeting.getStartOffset()));
                        ((NumberCell) getWidget(row, colTear)).setText(String.valueOf(-meeting.getEndOffset()));
                        ((Label) getWidget(row, colPubl)).setText(meeting.getMeetingTime(CONSTANTS));
                    }
                    dialog.hide();
                }
            });
            footer.addButton("cancel", MESSAGES.buttonCancel(), 75, new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    dialog.hide();
                }
            });
            simple.addBottomRow(footer);
            dialog.setWidget(simple);
            dialog.setText(MESSAGES.dlgChangeOffsets());
            dialog.setEscapeToHide(true);
            dialog.center();
        }

        @Override
        public String getName() {
            return MESSAGES.opChangeOffsets();
        }

        @Override
        public boolean isApplicable(EventMeetingRow data) {
            return isEditable() && data.getMeeting() != null
                    && (data.getMeeting().getId() == null || data.getMeeting().isCanEdit());
        }

        @Override
        public void execute(int row, EventMeetingRow data) {
        }
    });

    UniTimeTableHeader hName = new UniTimeTableHeader(MESSAGES.colName());
    header.add(hName);

    UniTimeTableHeader hSection = new UniTimeTableHeader(MESSAGES.colSection(),
            HasHorizontalAlignment.ALIGN_RIGHT);
    header.add(hSection);

    UniTimeTableHeader hType = new UniTimeTableHeader(MESSAGES.colType());
    header.add(hType);

    UniTimeTableHeader hTitle = new UniTimeTableHeader(MESSAGES.colTitle());
    header.add(hTitle);

    UniTimeTableHeader hNote = new UniTimeTableHeader(MESSAGES.colNote());
    header.add(hNote);

    UniTimeTableHeader hDate = new UniTimeTableHeader(MESSAGES.colDate());
    header.add(hDate);

    UniTimeTableHeader hTimePub = new UniTimeTableHeader(MESSAGES.colPublishedTime());
    header.add(hTimePub);
    UniTimeTableHeader hTimeAll = new UniTimeTableHeader(MESSAGES.colAllocatedTime());
    header.add(hTimeAll);
    UniTimeTableHeader hTimeSetup = new UniTimeTableHeader(MESSAGES.colSetupTimeShort(),
            HasHorizontalAlignment.ALIGN_RIGHT);
    header.add(hTimeSetup);
    UniTimeTableHeader hTimeTeardown = new UniTimeTableHeader(MESSAGES.colTeardownTimeShort(),
            HasHorizontalAlignment.ALIGN_RIGHT);
    header.add(hTimeTeardown);

    UniTimeTableHeader hLocation = new UniTimeTableHeader(MESSAGES.colLocation());
    header.add(hLocation);

    UniTimeTableHeader hCapacity = new UniTimeTableHeader(MESSAGES.colCapacity(),
            HasHorizontalAlignment.ALIGN_RIGHT);
    header.add(hCapacity);

    UniTimeTableHeader hEnrollment = new UniTimeTableHeader(MESSAGES.colEnrollment(),
            HasHorizontalAlignment.ALIGN_RIGHT);
    header.add(hEnrollment);

    UniTimeTableHeader hLimit = new UniTimeTableHeader(MESSAGES.colLimit(), HasHorizontalAlignment.ALIGN_RIGHT);
    header.add(hLimit);

    UniTimeTableHeader hSponsor = new UniTimeTableHeader(MESSAGES.colSponsorOrInstructor());
    header.add(hSponsor);

    UniTimeTableHeader hContact = new UniTimeTableHeader(MESSAGES.colMainContact());
    header.add(hContact);

    UniTimeTableHeader hApproval = new UniTimeTableHeader(MESSAGES.colApproval());
    header.add(hApproval);

    UniTimeTableHeader hLastChange = new UniTimeTableHeader(MESSAGES.colLastChange());
    header.add(hLastChange);

    addRow(null, header);

    final Operation titleOp = addHideOperation(hTitle, EventFlag.SHOW_TITLE, new Check() {
        @Override
        public boolean isChecked() {
            return true;
        }
    });
    final Operation noteOp = addHideOperation(hNote, EventFlag.SHOW_NOTE, new Check() {
        @Override
        public boolean isChecked() {
            return !titleOp.isApplicable();
        }
    });
    addHideOperation(hTimePub, EventFlag.SHOW_PUBLISHED_TIME, new Check() {
        @Override
        public boolean isChecked() {
            return !titleOp.isApplicable() && !noteOp.isApplicable();
        }
    });
    addHideOperation(hTimeAll, EventFlag.SHOW_ALLOCATED_TIME);
    addHideOperation(hTimeSetup, EventFlag.SHOW_SETUP_TIME);
    addHideOperation(hTimeTeardown, EventFlag.SHOW_TEARDOWN_TIME);
    addHideOperation(hCapacity, EventFlag.SHOW_CAPACITY);
    addHideOperation(hEnrollment, EventFlag.SHOW_ENROLLMENT);
    addHideOperation(hLimit, EventFlag.SHOW_LIMIT);
    addHideOperation(hSponsor, EventFlag.SHOW_SPONSOR);
    addHideOperation(hContact, EventFlag.SHOW_MAIN_CONTACT);
    addHideOperation(hApproval, EventFlag.SHOW_APPROVAL);
    addHideOperation(hLastChange, EventFlag.SHOW_LAST_CHANGE);

    Operation hideDuplicitiesForMeetings = new AriaOperation() {
        @Override
        public boolean isApplicable() {
            return iMode.hasFlag(ModeFlag.CanHideDuplicitiesForMeetings);
        }

        @Override
        public boolean hasSeparator() {
            return true;
        }

        @Override
        public void execute() {
            EventCookie.getInstance()
                    .setHideDuplicitiesForMeetings(!EventCookie.getInstance().isHideDuplicitiesForMeetings());
            int colDate = getHeader(MESSAGES.colDate()).getColumn();
            int colApproval = getHeader(MESSAGES.colApproval()).getColumn();
            for (int row = 1; row < getRowCount(); row++) {
                EventMeetingRow data = getData(row);
                if (data == null)
                    continue;
                EventInterface event = data.getEvent();
                String[] mtgs = new String[] { "", "", "", "", "", "", "" };
                String prevApproval = null;
                String[] prev = null;
                String prevSpan = null;
                String approval = "";
                boolean globalUnavailability = event != null && event.getId() != null && event.getId() < 0
                        && event.getType() == EventType.Unavailabile;
                for (MultiMeetingInterface m : EventInterface.getMultiMeetings(
                        data.getMeetings(getMeetingFilter()), true,
                        globalUnavailability ? null : iPropertiesProvider,
                        event == null ? null : event.getType())) {
                    String[] mtg = new String[] {
                            m.isArrangeHours() ? event.hasMessage()
                                    ? event.getMessage()
                                    : CONSTANTS.arrangeHours()
                                    : (m.getDays(CONSTANTS) + " "
                                            + (m.getNrMeetings() == 1
                                                    ? sDateFormatLong.format(m.getFirstMeetingDate())
                                                    : sDateFormatShort.format(m.getFirstMeetingDate()) + " - "
                                                            + sDateFormatLong.format(m.getLastMeetingDate()))),
                            m.isArrangeHours() && event.hasMessage() ? CONSTANTS.arrangeHours()
                                    : m.getMeetings().first().getMeetingTime(CONSTANTS),
                            m.getMeetings().first().getAllocatedTime(CONSTANTS),
                            String.valueOf(m.getMeetings().first().getStartOffset()),
                            String.valueOf(-m.getMeetings().first().getEndOffset()),
                            m.getLocationNameWithHint(),
                            (m.getMeetings().first().getLocation() == null ? ""
                                    : m.getMeetings().first().getLocation().hasSize()
                                            ? m.getMeetings().first().getLocation().getSize().toString()
                                            : MESSAGES.notApplicable()) };
                    if (!m.isArrangeHours() && !m.isPast()) {
                        SessionMonth.Flag dateFlag = (globalUnavailability || iPropertiesProvider == null ? null
                                : iPropertiesProvider.getDateFlag(event == null ? null : event.getType(),
                                        m.getFirstMeetingDate()));
                        if (dateFlag != null) {
                            switch (dateFlag) {
                            case FINALS:
                                mtg[0] = "<span class='finals' title=\"" + MESSAGES.hintFinals() + "\">"
                                        + mtg[0] + "</span>";
                                break;
                            case MIDTERMS:
                                mtg[0] = "<span class='midterms' title=\"" + MESSAGES.hintMidterms() + "\">"
                                        + mtg[0] + "</span>";
                                break;
                            case BREAK:
                                mtg[0] = "<span class='break' title=\"" + MESSAGES.hintBreak() + "\">" + mtg[0]
                                        + "</span>";
                                break;
                            case HOLIDAY:
                                mtg[0] = "<span class='holiday' title=\"" + MESSAGES.hintHoliday() + "\">"
                                        + mtg[0] + "</span>";
                                break;
                            case WEEKEND:
                                mtg[0] = "<span class='weekend' title=\"" + MESSAGES.hintWeekend() + "\">"
                                        + mtg[0] + "</span>";
                                break;
                            }
                        }
                    }
                    if (!m.isArrangeHours() && iPropertiesProvider != null && iPropertiesProvider.isTooEarly(
                            m.getMeetings().first().getStartSlot(), m.getMeetings().first().getEndSlot())) {
                        for (int i = 1; i <= 2; i++)
                            mtg[i] = "<span class='early' title=\"" + MESSAGES.hintTooEarly() + "\">" + mtg[i]
                                    + "</span>";
                    }
                    String span = "";
                    if (m.getApprovalStatus() == ApprovalStatus.Cancelled)
                        span = "cancelled-meeting";
                    else if (m.getApprovalStatus() == ApprovalStatus.Rejected)
                        span = "rejected-meeting";
                    else if (m.isPast())
                        span = "past-meeting";
                    for (int i = 0; i < mtgs.length; i++) {
                        mtgs[i] += (mtgs[i].isEmpty() ? "" : "<br>") + (prev != null && span.equals(prevSpan)
                                && prev[i == 6 ? i - 1 : i].equals(mtg[i == 6 ? i - 1 : i])
                                        ? MESSAGES.repeatingSymbol()
                                        : (!span.isEmpty() ? "<span class='" + span + "'>" : "") + mtg[i]
                                                + (!span.isEmpty() ? "</span>" : ""));
                    }
                    String thisApproval = (m.getApprovalStatus() == ApprovalStatus.Approved
                            ? sDateFormatApproval.format(m.getApprovalDate())
                            : m.getApprovalStatus() == ApprovalStatus.Cancelled ? MESSAGES.approvalCancelled()
                                    : m.getApprovalStatus() == ApprovalStatus.Rejected
                                            ? MESSAGES.approvalRejected()
                                            : "");

                    approval += (approval.isEmpty() ? "" : "<br>")
                            + (prev != null && span.equals(prevSpan) && prevApproval.equals(thisApproval)
                                    ? MESSAGES.repeatingSymbol()
                                    : (m.getApprovalStatus() == ApprovalStatus.Approved
                                            ? m.isPast() ? "<span class='past-meeting'>"
                                                    + sDateFormatApproval.format(m.getApprovalDate())
                                                    + "</span>"
                                                    : sDateFormatApproval.format(m.getApprovalDate())
                                            : m.getApprovalStatus() == ApprovalStatus.Cancelled
                                                    ? "<span class='cancelled-meeting'>"
                                                            + MESSAGES.approvalCancelled() + "</span>"
                                                    : m.getApprovalStatus() == ApprovalStatus.Rejected
                                                            ? "<span class='rejected-meeting'>"
                                                                    + MESSAGES.approvalRejected() + "</span>"
                                                            : event != null
                                                                    && event.getType() == EventType.Unavailabile
                                                                            ? ""
                                                                            : m.getFirstMeetingDate() == null
                                                                                    ? ""
                                                                                    : m.isPast()
                                                                                            ? "<span class='not-approved-past'>"
                                                                                                    + MESSAGES
                                                                                                            .approvalNotApprovedPast()
                                                                                                    + "</span>"
                                                                                            : event != null
                                                                                                    && event.getExpirationDate() != null
                                                                                                            ? "<span class='not-approved'>"
                                                                                                                    + MESSAGES
                                                                                                                            .approvalExpire(
                                                                                                                                    sDateFormatExpiration
                                                                                                                                            .format(event
                                                                                                                                                    .getExpirationDate()))
                                                                                                                    + "</span>"
                                                                                                            : "<span class='not-approved'>"
                                                                                                                    + MESSAGES
                                                                                                                            .approvalNotApproved()
                                                                                                                    + "</span>"));
                    if (EventCookie.getInstance().isHideDuplicitiesForMeetings()) {
                        prev = mtg;
                        prevSpan = span;
                        prevApproval = thisApproval;
                    }
                }
                for (int i = 0; i < mtgs.length; i++) {
                    if (i == 3 || i == 4 || i == 6)
                        setWidget(row, colDate + i, new NumberCell(mtgs[i]));
                    else
                        setWidget(row, colDate + i, new HTML(mtgs[i], false));
                }
                setWidget(row, colApproval, new HTML(approval == null ? "" : approval, false));
            }
        }

        @Override
        public String getName() {
            return EventCookie.getInstance().isHideDuplicitiesForMeetings()
                    ? MESSAGES.opUncheck(MESSAGES.opHideRepeatingInformation())
                    : MESSAGES.opCheck(MESSAGES.opHideRepeatingInformation());
        }

        @Override
        public String getAriaLabel() {
            return EventCookie.getInstance().isHideDuplicitiesForMeetings()
                    ? ARIA.opUncheck(MESSAGES.opHideRepeatingInformation())
                    : ARIA.opCheck(MESSAGES.opHideRepeatingInformation());
        }
    };
    hDate.addOperation(hideDuplicitiesForMeetings);
    hTimePub.addOperation(hideDuplicitiesForMeetings);
    hTimeAll.addOperation(hideDuplicitiesForMeetings);
    hTimeSetup.addOperation(hideDuplicitiesForMeetings);
    hTimeTeardown.addOperation(hideDuplicitiesForMeetings);
    hLocation.addOperation(hideDuplicitiesForMeetings);
    hCapacity.addOperation(hideDuplicitiesForMeetings);
    hApproval.addOperation(hideDuplicitiesForMeetings);

    addSortByOperation(hName, EventMeetingSortBy.NAME);
    addSortByOperation(hSection, EventMeetingSortBy.SECTION);
    addSortByOperation(hType, EventMeetingSortBy.TYPE);
    addSortByOperation(hTitle, EventMeetingSortBy.TITLE);
    addSortByOperation(hNote, EventMeetingSortBy.NOTE);
    addSortByOperation(hDate, EventMeetingSortBy.DATE);
    addSortByOperation(hTimePub, EventMeetingSortBy.PUBLISHED_TIME);
    addSortByOperation(hTimeAll, EventMeetingSortBy.ALLOCATED_TIME);
    addSortByOperation(hTimeSetup, EventMeetingSortBy.SETUP_TIME);
    addSortByOperation(hTimeTeardown, EventMeetingSortBy.TEARDOWN_TIME);
    addSortByOperation(hLocation, EventMeetingSortBy.LOCATION);
    addSortByOperation(hCapacity, EventMeetingSortBy.CAPACITY);
    addSortByOperation(hEnrollment, EventMeetingSortBy.ENROLLMENT);
    addSortByOperation(hLimit, EventMeetingSortBy.LIMIT);
    addSortByOperation(hSponsor, EventMeetingSortBy.SPONSOR);
    addSortByOperation(hContact, EventMeetingSortBy.MAIN_CONTACT);
    addSortByOperation(hApproval, EventMeetingSortBy.APPROVAL);
    addSortByOperation(hLastChange, EventMeetingSortBy.LAST_CHANGE);

    hTimes.addOperation(new AriaOperation() {
        @Override
        public void execute() {
            EventCookie.getInstance().setAutomaticallyApproveNewMeetings(
                    !EventCookie.getInstance().isAutomaticallyApproveNewMeetings());
            for (int row = 1; row < getRowCount(); row++) {
                EventMeetingRow data = getData(row);
                if (data.hasMeeting() && data.getMeeting().getId() == null && data.getMeeting().isCanApprove()
                        && data.hasEvent() && (data.getEvent().getType() == EventType.Special
                                || data.getEvent().getType() == EventType.Course)) {
                    HTML approval = (HTML) getWidget(row, getHeader(MESSAGES.colApproval()).getColumn());
                    if (EventCookie.getInstance().isAutomaticallyApproveNewMeetings()) {
                        approval.setStyleName("new-approved-meeting");
                        approval.setText(MESSAGES.approvelNewApprovedMeeting());
                    } else {
                        approval.setStyleName("new-meeting");
                        approval.setText(MESSAGES.approvalNewMeeting());
                    }
                }
            }
            ValueChangeEvent.fire(EventMeetingTable.this, getValue());
        }

        @Override
        public boolean isApplicable() {
            for (int row = 1; row < getRowCount(); row++) {
                EventMeetingRow data = getData(row);
                if (data.hasMeeting() && data.getMeeting().getId() == null && data.getMeeting().isCanApprove()
                        && data.hasEvent() && (data.getEvent().getType() == EventType.Special
                                || data.getEvent().getType() == EventType.Course))
                    return true;
            }
            return false;
        }

        @Override
        public boolean hasSeparator() {
            return true;
        }

        @Override
        public String getName() {
            return EventCookie.getInstance().isAutomaticallyApproveNewMeetings()
                    ? MESSAGES.opUncheck(MESSAGES.opAutomaticApproval())
                    : MESSAGES.opCheck(MESSAGES.opAutomaticApproval());
        }

        @Override
        public String getAriaLabel() {
            return EventCookie.getInstance().isAutomaticallyApproveNewMeetings()
                    ? ARIA.opUncheck(MESSAGES.opAutomaticApproval())
                    : ARIA.opCheck(MESSAGES.opAutomaticApproval());
        }

    });

    for (int i = 0; i < getCellCount(0); i++)
        getCellFormatter().setStyleName(0, i, "unitime-ClickableTableHeaderNoBorderLine");

    resetColumnVisibility();
}