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

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

Introduction

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

Prototype

@Override
    public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler) 

Source Link

Usage

From source file:org.drools.guvnor.client.asseteditor.drools.modeldriven.ui.RuleModellerConditionSelectorPopup.java

License:Apache License

@Override
public Widget getContent() {
    if (position == null) {
        positionCbo.addItem(Constants.INSTANCE.Bottom(), String.valueOf(this.model.lhs.length));
        positionCbo.addItem(Constants.INSTANCE.Top(), "0");
        for (int i = 1; i < model.lhs.length; i++) {
            positionCbo.addItem(Constants.INSTANCE.Line0(i), String.valueOf(i));
        }/*w  w w . j  a  v a 2 s  . c  o  m*/
    } else {
        //if position is fixed, we just add one element to the drop down.
        positionCbo.addItem(String.valueOf(position));
        positionCbo.setSelectedIndex(0);
    }

    if (completions.getDSLConditions().length == 0 && completions.getFactTypes().length == 0) {
        layoutPanel.addRow(new HTML("<div class='highlight'>" + Constants.INSTANCE.NoModelTip() + "</div>"));
    }

    //only show the drop down if we are not using fixed position.
    if (position == null) {
        HorizontalPanel hp0 = new HorizontalPanel();
        hp0.add(new HTML(Constants.INSTANCE.PositionColon()));
        hp0.add(positionCbo);
        hp0.add(new InfoPopup(Constants.INSTANCE.PositionColon(),
                Constants.INSTANCE.ConditionPositionExplanation()));
        layoutPanel.addRow(hp0);
    }

    choices = makeChoicesListBox();
    choicesPanel.add(choices);
    layoutPanel.addRow(choicesPanel);

    HorizontalPanel hp = new HorizontalPanel();
    Button ok = new Button(Constants.INSTANCE.OK());
    hp.add(ok);
    ok.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            selectSomething();
        }
    });

    Button cancel = new Button(Constants.INSTANCE.Cancel());
    hp.add(cancel);
    cancel.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            hide();
        }
    });

    CheckBox chkOnlyDisplayDSLConditions = new CheckBox();
    chkOnlyDisplayDSLConditions.setText(Constants.INSTANCE.OnlyDisplayDSLConditions());
    chkOnlyDisplayDSLConditions.setValue(bOnlyShowDSLConditions);
    chkOnlyDisplayDSLConditions.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        public void onValueChange(ValueChangeEvent<Boolean> event) {
            bOnlyShowDSLConditions = event.getValue();
            choicesPanel.setWidget(makeChoicesListBox());
        }

    });

    layoutPanel.addRow(chkOnlyDisplayDSLConditions);

    layoutPanel.addRow(hp);

    this.setAfterShow(new Command() {

        public void execute() {
            choices.setFocus(true);
        }
    });

    return layoutPanel;
}

From source file:org.drools.guvnor.client.decisiontable.widget.auditlog.AuditLogViewImpl.java

License:Apache License

private Widget makeEventTypeCheckBox(final String eventType, final Boolean isEnabled) {
    final CheckBox chkEventType = new CheckBox(AuditLogEntryCellHelper.getEventTypeDisplayText(eventType));
    chkEventType.setValue(Boolean.TRUE.equals(isEnabled));
    chkEventType.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override//from   ww w  .  j av a  2 s  . com
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            auditLog.getAuditLogFilter().getAcceptedTypes().put(eventType, event.getValue());
        }

    });

    return chkEventType;
}

From source file:org.drools.guvnor.client.table.ColumnPicker.java

License:Apache License

public ToggleButton createToggleButton() {
    final ToggleButton button = new ToggleButton(COLUMN_PICKER_IMAGE);
    final PopupPanel popup = new PopupPanel(true);
    popup.addCloseHandler(new CloseHandler<PopupPanel>() {
        public void onClose(CloseEvent<PopupPanel> popupPanelCloseEvent) {
            button.setDown(false);//  w  w  w.  j  ava2  s. c  o m
        }
    });
    VerticalPanel popupContent = new VerticalPanel();
    for (final ColumnMeta<T> columnMeta : columnMetaList) {
        final CheckBox checkBox = new CheckBox(columnMeta.getHeader().getValue());
        checkBox.setValue(columnMeta.isVisible());
        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                boolean visible = booleanValueChangeEvent.getValue();
                if (visible) {
                    // WORKAROUND because CellTable does not support insertColumn at this time
                    for (ColumnMeta<T> resettingColumnMeta : columnMetaList) {
                        if (resettingColumnMeta.isVisible()) {
                            cellTable.removeColumn(resettingColumnMeta.getColumn());
                        }
                    }
                    columnMeta.setVisible(visible);
                    for (ColumnMeta<T> resettingColumnMeta : columnMetaList) {
                        if (resettingColumnMeta.isVisible()) {
                            cellTable.addColumn(resettingColumnMeta.getColumn(),
                                    resettingColumnMeta.getHeader());
                        }
                    }
                } else {
                    columnMeta.setVisible(visible);
                    cellTable.removeColumn(columnMeta.getColumn());
                }
            }
        });
        popupContent.add(checkBox);
    }
    popup.add(popupContent);
    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (button.isDown()) {
                popup.setPopupPosition(button.getAbsoluteLeft(),
                        button.getAbsoluteTop() + button.getOffsetHeight());
                popup.show();
            }
            // Note: no need to hide the popup when clicked when down,
            // because clicking anywhere outside the popup will hide the popup
        }
    });
    return button;
}

From source file:org.drools.guvnor.client.widgets.tables.ColumnPicker.java

License:Apache License

public ToggleButton createToggleButton() {
    final ToggleButton button = new ToggleButton(COLUMN_PICKER_IMAGE);
    final PopupPanel popup = new PopupPanel(true);
    popup.addAutoHidePartner(button.getElement());
    popup.addCloseHandler(new CloseHandler<PopupPanel>() {
        public void onClose(CloseEvent<PopupPanel> popupPanelCloseEvent) {
            button.setDown(false);/*from   w w w.  j  a  va 2  s.c  om*/
        }
    });
    VerticalPanel popupContent = new VerticalPanel();
    for (final ColumnMeta<T> columnMeta : columnMetaList) {
        final CheckBox checkBox = new CheckBox(columnMeta.getHeader().getValue());
        checkBox.setValue(columnMeta.isVisible());
        checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
                boolean visible = booleanValueChangeEvent.getValue();
                if (visible) {
                    // WORKAROUND because CellTable does not support insertColumn at this time
                    for (ColumnMeta<T> resettingColumnMeta : columnMetaList) {
                        if (resettingColumnMeta.isVisible()) {
                            cellTable.removeColumn(resettingColumnMeta.getColumn());
                        }
                    }
                    columnMeta.setVisible(visible);
                    for (ColumnMeta<T> resettingColumnMeta : columnMetaList) {
                        if (resettingColumnMeta.isVisible()) {
                            cellTable.addColumn(resettingColumnMeta.getColumn(),
                                    resettingColumnMeta.getHeader());
                        }
                    }
                } else {
                    columnMeta.setVisible(visible);
                    cellTable.removeColumn(columnMeta.getColumn());
                }
            }
        });
        popupContent.add(checkBox);
    }
    popup.add(popupContent);
    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (button.isDown()) {
                popup.setPopupPosition(button.getAbsoluteLeft(),
                        button.getAbsoluteTop() + button.getOffsetHeight());
                popup.show();
            } else {
                popup.hide(false);
            }
        }
    });
    return button;
}

From source file:org.eclipse.che.ide.processes.runtime.CellTableRuntimeInfoWidgetFactory.java

License:Open Source License

@Override
public Widget create(String machineName, List<RuntimeInfo> runtimeList) {
    VerticalPanel panel = new VerticalPanel();
    panel.ensureDebugId("runtimeInfoVerticalPanel");
    panel.setWidth("100%");

    Label caption = new Label(locale.cellTableCaption(machineName));
    caption.ensureDebugId("runtimeInfoCellTableCaption");
    caption.addStyleName(resources.cellTableStyle().cellTableCaption());

    HorizontalPanel hPanel = new HorizontalPanel();
    hPanel.setWidth("100%");
    hPanel.ensureDebugId("runtimeInfoCellTableHeaderWrapper");
    hPanel.add(caption);/*from   w  w  w  .  j  ava 2s .  c  o m*/

    ListDataProvider<RuntimeInfo> dataProvider = new ListDataProvider<>(runtimeList);

    CheckBox hideCheckBox = new CheckBox("Hide internal servers");
    hideCheckBox.addValueChangeHandler(event -> {
        if (event.getValue()) { // if hide = true
            dataProvider.setList(
                    runtimeList.stream().filter(info -> !isNullOrEmpty(info.getPort())).collect(toList()));
        } else {
            dataProvider.setList(runtimeList);
        }
        dataProvider.refresh();
    });
    hideCheckBox.addStyleName(resources.cellTableStyle().cellTableHideServersCheckBox());
    hideCheckBox.ensureDebugId("runtimeInfoHideServersCheckBox");

    hPanel.add(hideCheckBox);

    panel.add(hPanel);
    panel.add(createCellTable(dataProvider));

    return new ScrollPanel(panel);
}

From source file:org.eclipse.emf.edit.ui.EditorEntryPoint.java

License:Open Source License

public void onModuleLoad() {
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory();
    composedAdapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
    configureItemProviderAdapterFactories(composedAdapterFactory);
    composedAdapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());

    final BasicCommandStack commandStack = new BasicCommandStack();
    final AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(composedAdapterFactory,
            commandStack);//  w  w w .ja v  a2 s . c o m

    final ResourceSet resourceSet = editingDomain.getResourceSet();
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
            .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new ResourceFactoryImpl() {
                @Override
                public Resource createResource(URI uri) {
                    return new BinaryResourceImpl(uri);
                }
            });

    final URIServiceAsync uriService = GWT.create(URIService.class);
    URIServiceCallback uriServiceCallback = new URIServiceCallback(uriService);
    resourceSet.getURIConverter().getURIHandlers().add(uriServiceCallback);

    final List<Resource> originalResources = new ArrayList<Resource>();

    Resource listingResource = resourceSet.getResource(URI.createURI("datastore:/"), new Callback<Resource>() {
        public void onFailure(Throwable caught) {
            System.err.println("Failed");
            caught.printStackTrace();
        }

        public void onSuccess(Resource result) {
            EAnnotation eAnnotation = (EAnnotation) result.getContents().get(0);
            for (Map.Entry<String, String> entry : eAnnotation.getDetails()) {
                resourceSet.createResource(URI.createURI(entry.getKey()));
            }
            originalResources.clear();
            originalResources.addAll(resourceSet.getResources());
        }
    });
    resourceSet.getResources().remove(listingResource);

    registerPackages(resourceSet.getPackageRegistry());

    final AdapterFactoryItemDelegator itemDelegator = new AdapterFactoryItemDelegator(composedAdapterFactory);

    DockLayoutPanel mainPanel = new DockLayoutPanel(Unit.PX);
    mainPanel.setStyleName("Main", true);
    mainPanel.setHeight("100%");

    FlowPanel headerPanel = new FlowPanel();
    headerPanel.setStyleName("Header", true);

    final Label header = new Label(getApplicationTitle());
    header.setStyleName("HeaderLabel", true);

    headerPanel.add(header);

    mainPanel.addNorth(headerPanel, 56.0);

    DockLayoutPanel bodyPanel = new DockLayoutPanel(Unit.PX);
    bodyPanel.setStyleName("Body", true);
    bodyPanel.setHeight("100%");

    mainPanel.add(bodyPanel);

    FlowPanel toolBar = new FlowPanel();
    toolBar.setStyleName("ToolBar", true);

    SplitLayoutPanel contentPanel = new SplitLayoutPanel();
    contentPanel.setStyleName("Content", true);

    DockLayoutPanel propertiesPanel = new DockLayoutPanel(Unit.PX);
    propertiesPanel.setStyleName("Properties", true);
    propertiesPanel.setHeight("100%");

    FlowPanel propertiesTitlePanel = new FlowPanel();
    propertiesTitlePanel.setStyleName("PropertiesTitle", true);

    final Label title = new Label("Properties");
    title.setStyleName("PropertiesTitleLabel", true);

    propertiesTitlePanel.add(title);

    propertiesPanel.addNorth(propertiesTitlePanel, 28.0);

    final Grid properties = new Grid();
    properties.setWidth("100%");
    ScrollPanel propertiesScrollPanel = new ScrollPanel();
    propertiesScrollPanel.add(properties);

    propertiesPanel.add(propertiesScrollPanel);

    final Button createButton = new Button();
    createButton.setText("Create...");
    createButton.setStyleName("ToolBarButtonLeftMargin");

    toolBar.add(createButton);

    final Button deleteButton = new Button();
    deleteButton.setText("Delete");
    final CommandHandler deleteCommandHandler = new CommandHandler(editingDomain, deleteButton) {
        @Override
        public Command createCommand(Object value) {
            if (value instanceof Resource) {
                final Resource resource = (Resource) value;
                final Command deleteContentsCommand = DeleteCommand.create(editingDomain,
                        resource.getContents());
                final RemoveCommand removeResourceCommand = new RemoveCommand(editingDomain,
                        resourceSet.getResources(), resource);
                return new CompoundCommand() {
                    @Override
                    protected boolean prepare() {
                        return true;
                    }

                    @Override
                    public void execute() {
                        appendAndExecute(deleteContentsCommand);
                        appendAndExecute(removeResourceCommand);
                    }
                };
            } else {
                return DeleteCommand.create(editingDomain, value);
            }
        }
    };
    deleteButton.setStyleName("ToolBarButton");

    toolBar.add(deleteButton);

    final Button validateButton = new Button();
    validateButton.setText("Validate");
    validateButton.setStyleName("ToolBarButtonLeftMargin");

    toolBar.add(validateButton);

    final Button saveButton = new Button();
    saveButton.setText("Save");
    saveButton.setStyleName("ToolBarButton");

    toolBar.add(saveButton);

    final Button undoButton = new Button();
    undoButton.setText("Undo");
    undoButton.setStyleName("ToolBarButtonLeftMargin");

    toolBar.add(undoButton);

    final Button redoButton = new Button();
    redoButton.setText("Redo");
    redoButton.setStyleName("ToolBarButton");

    toolBar.add(redoButton);

    final Button cutButton = new Button();
    cutButton.setText("Cut");
    final CommandHandler cutCommandHandler = new CommandHandler(editingDomain, cutButton) {
        @Override
        public Command createCommand(Object value) {
            return CutToClipboardCommand.create(editingDomain, value);
        }
    };
    cutButton.setStyleName("ToolBarButtonLeftMargin");

    toolBar.add(cutButton);

    final Button copyButton = new Button();
    copyButton.setText("Copy");
    final CommandHandler copyCommandHandler = new CommandHandler(editingDomain, copyButton) {
        @Override
        public Command createCommand(Object value) {
            return value instanceof EObject ? CopyToClipboardCommand.create(editingDomain, value)
                    : UnexecutableCommand.INSTANCE;
        }
    };
    copyButton.setStyleName("ToolBarButton");

    toolBar.add(copyButton);

    final Button pasteButton = new Button();
    pasteButton.setText("Paste");
    final CommandHandler pasteCommandHandler = new CommandHandler(editingDomain, pasteButton) {
        @Override
        public Command createCommand(Object value) {
            return PasteFromClipboardCommand.create(editingDomain, value, null);
        }
    };
    pasteButton.setStyleName("ToolBarButton");

    toolBar.add(pasteButton);

    final Button upButton = new Button();
    upButton.setText("Up ^");
    final CommandHandler upCommandHandler = new CommandHandler(editingDomain, upButton) {
        @Override
        public Command createCommand(Object value) {
            Object owner = editingDomain.getParent(value);
            if (owner != null) {
                List<?> children = new ArrayList<Object>(editingDomain.getChildren(owner));
                int index = children.indexOf(value);
                if (index != -1) {
                    return MoveCommand.create(editingDomain, owner, null, value, index - 1);
                }
            }
            return UnexecutableCommand.INSTANCE;
        }
    };
    upButton.setStyleName("ToolBarButtonLeftMargin");

    toolBar.add(upButton);

    final Button downButton = new Button();
    downButton.setText("Down v");
    final CommandHandler downCommandHandler = new CommandHandler(editingDomain, downButton) {
        @Override
        public Command createCommand(Object value) {
            Object owner = editingDomain.getParent(value);
            if (owner != null) {
                List<?> children = new ArrayList<Object>(editingDomain.getChildren(owner));
                int index = children.indexOf(value);
                if (index != -1) {
                    return MoveCommand.create(editingDomain, owner, null, value, index + 1);
                }
            }
            return UnexecutableCommand.INSTANCE;
        }
    };
    downButton.setStyleName("ToolBarButton");

    toolBar.add(downButton);

    final Button navigateButton = new Button();
    navigateButton.setText("Navigate");
    navigateButton.setEnabled(false);
    navigateButton.setStyleName("ToolBarButtonLeftMargin");

    toolBar.add(navigateButton);

    final SingleSelectionModel<Object> treeSelection = new SingleSelectionModel<Object>();
    final Collection<Runnable> propertyUpdater = new HashSet<Runnable>();

    TreeViewModel treeViewModel = new TreeViewModel() {
        public <T> NodeInfo<?> getNodeInfo(final T value) {
            final ListDataProvider<Object> abstractListViewAdapter = new ListDataProvider<Object>() {
                int size;

                class NodeAdapter extends AdapterImpl implements INotifyChangedListener {
                    Set<Object> children = new HashSet<Object>();

                    @Override
                    public void notifyChanged(Notification msg) {
                        if (msg.getEventType() != Notification.REMOVING_ADAPTER) {
                            update();
                            if (!(msg.getNotifier() instanceof EObject)) {
                                for (Runnable runnable : propertyUpdater) {
                                    runnable.run();
                                }
                            }
                        }
                    }

                    public void listenTo(Object target) {
                        if (target instanceof Notifier) {
                            ((Notifier) target).eAdapters().add(this);
                        } else if (target instanceof IChangeNotifier) {
                            ((IChangeNotifier) target).addListener(this);
                        }
                    }

                    public void stopListeningTo(Object target) {
                        if (target instanceof Notifier) {
                            ((Notifier) target).eAdapters().remove(this);
                        } else if (target instanceof IChangeNotifier) {
                            ((IChangeNotifier) target).removeListener(this);
                        }
                    }

                    public void listenTo(List<Object> children) {
                        // TODO
                        // I don't know how to update just one child. :-(

                        boolean isListeningToValue = !this.children.isEmpty();
                        Set<Object> oldChildren = new HashSet<Object>(this.children);
                        for (Object child : children) {
                            if (this.children.contains(child)) {
                                oldChildren.remove(child);
                            } else {
                                this.children.add(child);
                                listenTo(child);
                            }
                        }
                        for (Object child : oldChildren) {
                            stopListeningTo(child);
                            this.children.remove(child);
                        }
                        if (isListeningToValue) {
                            if (children.isEmpty()) {
                                stopListeningTo(value);
                            }
                        } else if (!children.isEmpty()) {
                            listenTo(value);
                        }
                    }
                }

                protected NodeAdapter nodeAdapter = new NodeAdapter();

                @Override
                protected void onRangeChanged(HasData<Object> display) {
                    if (value instanceof Resource) {
                        Resource resource = (Resource) value;
                        if (!resource.isLoaded()) {
                            try {
                                resource.load(resourceSet.getLoadOptions());
                            } catch (IOException e) {
                                // Ignore.
                            }
                        }
                    }
                    update();
                }

                protected void update() {
                    Collection<?> children = itemDelegator.getChildren(value);
                    ArrayList<Object> childrenList = new ArrayList<Object>(children);
                    nodeAdapter.listenTo(childrenList);
                    int size = children.size();
                    if (this.size < size) {
                        updateRowCount(size, true);
                        this.size = size;
                    } else {
                        // Pad with dummy objects.
                        for (int i = size; i < this.size; ++i) {
                            childrenList.add(new Object());
                        }
                    }
                    updateRowData(0, childrenList);
                    if (this.size > size) {
                        updateRowCount(size, true);
                        this.size = size;
                    }
                }
            };

            Cell<Object> cell = new AbstractCell<Object>() {
                @Override
                public void render(Context context, Object value, SafeHtmlBuilder safeHtmlBuilder) {
                    StringBuilder sb = new StringBuilder();
                    Object image = itemDelegator.getImage(value);
                    if (image instanceof ImageResource) {
                        ImageResource imageResource = (ImageResource) image;
                        sb.append("<div style='position:relative;padding-left:");
                        sb.append(imageResource.getWidth() + 6);
                        sb.append("px;'>");
                        sb.append("<div style=\"position:absolute;left:0px;top:0px;height:100%;");
                        sb.append("width:").append(imageResource.getWidth()).append("px;");
                        sb.append("background:url('").append(imageResource.getSafeUri()).append("') ");
                        sb.append("no-repeat scroll center center transparent;");
                        sb.append("\"></div>");
                        sb.append(itemDelegator.getText(value));
                        sb.append("</div>");
                    } else if (image instanceof ComposedImage) {
                        ComposedImage composedImage = (ComposedImage) image;
                        List<ComposedImage.Size> sizes = new ArrayList<ComposedImage.Size>();
                        List<Object> images = new ArrayList<Object>(composedImage.getImages());
                        List<ImageData> nestedImagesData = new ArrayList<ImageData>();
                        for (Object nestedImage : images) {
                            ImageData nestedImageData = getImageData(nestedImage);
                            ComposedImage.Size size = new ComposedImage.Size();
                            size.height = nestedImageData.height;
                            size.width = nestedImageData.width;
                            sizes.add(size);
                            nestedImagesData.add(nestedImageData);
                        }
                        ComposedImage.Size size = composedImage.getSize(sizes);
                        sb.append("<div style='position:relative;padding-left:");
                        sb.append(size.width + 6);
                        sb.append("px;'>");
                        List<ComposedImage.Point> drawPoints = composedImage.getDrawPoints(size);
                        int i = 0;
                        for (ComposedImage.Point drawPoint : drawPoints) {
                            ImageResource nestedImage = (ImageResource) images.get(i++);
                            sb.append("<div style=\"position:absolute;left:").append(drawPoint.x)
                                    .append("px;top:").append(drawPoint.y).append("px;height:100%;");
                            sb.append("width:").append(nestedImage.getWidth()).append("px;");
                            sb.append("background:url('").append(nestedImage.getSafeUri()).append("') ");
                            sb.append("no-repeat scroll center center transparent;");
                            sb.append("\"></div>");
                        }
                        sb.append(itemDelegator.getText(value));
                        sb.append("</div>");
                    } else {
                        sb.append(itemDelegator.getText(value));
                    }
                    safeHtmlBuilder.appendHtmlConstant(sb.toString());
                }
            };
            return new DefaultNodeInfo<Object>(abstractListViewAdapter, cell, treeSelection, null);
        }

        public boolean isLeaf(Object value) {
            return !itemDelegator.hasChildren(value);
        }
    };

    treeSelection.setSelected(resourceSet, true);
    final MyCellTree cellTree = new MyCellTree(treeViewModel,
            new ItemProvider(Collections.singleton(resourceSet)));
    ScrollPanel treeScrollPanel = new ScrollPanel();
    treeScrollPanel.add(cellTree);

    class NavigationListener {
        Object selection;

        {
            navigateButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    final Object oldSelection = treeSelection.getSelectedObject();
                    Object newSelection = selection;
                    cellTree.expand(editingDomain.getTreePath(editingDomain.getParent(newSelection)));
                    treeSelection.setSelected(newSelection, true);
                    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                        public void execute() {
                            setSelection(oldSelection);
                        }
                    });
                }
            });
        }

        public void listenTo(final ListBox listBox, final List<?> values) {
            listBox.addFocusHandler(new FocusHandler() {
                protected HandlerRegistration changeHandlerRegistration;

                {
                    listBox.addBlurHandler(new BlurHandler() {
                        public void onBlur(BlurEvent event) {
                            if (changeHandlerRegistration != null) {
                                changeHandlerRegistration.removeHandler();
                                changeHandlerRegistration = null;
                            }
                        }
                    });
                }

                public void onFocus(FocusEvent event) {
                    updateSelection();
                    changeHandlerRegistration = listBox.addChangeHandler(new ChangeHandler() {
                        public void onChange(ChangeEvent event) {
                            updateSelection();
                        }
                    });
                }

                void updateSelection() {
                    int selectedIndex = listBox.getSelectedIndex();
                    setSelection(selectedIndex == -1 || selectedIndex >= values.size() ? null
                            : values.get(selectedIndex));
                }
            });
        }

        protected void setSelection(Object object) {
            if (object != selection) {
                selection = object;
                navigateButton.setEnabled(selection != null);
            }
        }
    }
    final NavigationListener navigationListener = new NavigationListener();

    treeSelection.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        protected Object oldSelection;

        public void onSelectionChange(SelectionChangeEvent event) {
            final Object object = treeSelection.getSelectedObject();

            deleteCommandHandler.setSelection(object);
            cutCommandHandler.setSelection(object);
            pasteCommandHandler.setSelection(object);
            copyCommandHandler.setSelection(object);
            upCommandHandler.setSelection(object);
            downCommandHandler.setSelection(object);
            createButton.setEnabled(object instanceof Resource || object instanceof ResourceSet
                    || !editingDomain.getNewChildDescriptors(object, null).isEmpty());

            if (oldSelection == object) {
                for (Runnable runnable : propertyUpdater) {
                    runnable.run();
                }
            } else {
                navigationListener.setSelection(null);

                oldSelection = object;

                List<IItemPropertyDescriptor> propertyDescriptors = itemDelegator
                        .getPropertyDescriptors(object);
                if (propertyDescriptors != null) {
                    properties.clear();
                    propertyUpdater.clear();
                    int size = propertyDescriptors.size();
                    properties.resize(size, 2);
                    properties.getColumnFormatter().setWidth(0, "10%");
                    properties.getColumnFormatter().setWidth(1, "90%");
                    for (int i = 0; i < size; ++i) {
                        final IItemPropertyDescriptor propertyDescriptor = propertyDescriptors.get(i);
                        properties.setText(i, 0, propertyDescriptor.getDisplayName(object));
                        Widget widget = null;
                        final IItemLabelProvider itemLabelProvider = propertyDescriptor
                                .getLabelProvider(object);
                        final Object feature = propertyDescriptor.getFeature(object);
                        if (feature instanceof EReference[]) {
                            final ItemPropertyDescriptorFeatureEditor dialog = new ItemPropertyDescriptorFeatureEditor(
                                    object, true, propertyDescriptor) {
                                @Override
                                protected void hook(ListBox listBox, List<?> values) {
                                    navigationListener.listenTo(listBox, values);
                                }
                            };
                            dialog.update();
                            widget = dialog;
                            propertyUpdater.add(new Runnable() {
                                public void run() {
                                    dialog.update();
                                }
                            });
                        } else if (feature instanceof EStructuralFeature) {
                            final EStructuralFeature eStructureFeature = (EStructuralFeature) feature;
                            final EClassifier eType = eStructureFeature.getEType();
                            final Collection<?> choiceOfValues = propertyDescriptor.getChoiceOfValues(object);
                            if (choiceOfValues != null) {
                                final List<?> listOfValues = new ArrayList<Object>(
                                        propertyDescriptor.getChoiceOfValues(object));
                                if (propertyDescriptor.isMany(object)) {
                                    boolean valid = true;
                                    for (Object choice : choiceOfValues) {
                                        if (!eType.isInstance(choice)) {
                                            valid = false;
                                            break;
                                        }
                                    }

                                    if (valid) {
                                        final ItemPropertyDescriptorFeatureEditor dialog = new ItemPropertyDescriptorFeatureEditor(
                                                object, true, propertyDescriptor) {
                                            @Override
                                            protected void hook(ListBox listBox, List<?> values) {
                                                navigationListener.listenTo(listBox, values);
                                            }
                                        };
                                        dialog.update();
                                        widget = dialog;
                                        propertyUpdater.add(new Runnable() {
                                            public void run() {
                                                dialog.update();
                                            }
                                        });
                                    }
                                }
                                if (widget == null) {
                                    final ListBox listBox = new ListBox();
                                    widget = listBox;
                                    listBox.setVisibleItemCount(1);
                                    Runnable runnable = new Runnable() {
                                        public void run() {
                                            listBox.clear();
                                            navigationListener.listenTo(listBox, listOfValues);
                                            Object propertyValue = itemDelegator.getEditableValue(
                                                    propertyDescriptor.getPropertyValue(object));
                                            for (Object value : choiceOfValues) {
                                                listBox.addItem(itemLabelProvider.getText(value));
                                                if (value == null ? propertyValue == null
                                                        : value.equals(propertyValue)) {
                                                    listBox.setSelectedIndex(listBox.getItemCount() - 1);
                                                }
                                            }
                                        }
                                    };
                                    listBox.addChangeHandler(new ChangeHandler() {
                                        public void onChange(ChangeEvent event) {
                                            Object value = listOfValues.get(listBox.getSelectedIndex());
                                            propertyDescriptor.setPropertyValue(object, value);
                                        }
                                    });
                                    runnable.run();
                                    propertyUpdater.add(runnable);
                                }
                            } else if (eType instanceof EDataType) {
                                final EDataType eDataType = (EDataType) eType;
                                if (eDataType.isSerializable()) {
                                    if (propertyDescriptor.isMany(object)) {
                                        final ItemPropertyDescriptorFeatureEditor dialog = new ItemPropertyDescriptorFeatureEditor(
                                                object, propertyDescriptor) {
                                            @Override
                                            protected void hook(ListBox listBox, List<?> values) {
                                                navigationListener.listenTo(listBox, values);
                                            }
                                        };
                                        dialog.update();
                                        widget = dialog;
                                        propertyUpdater.add(new Runnable() {
                                            public void run() {
                                                dialog.update();
                                            }
                                        });
                                    } else {
                                        if (eDataType.getInstanceClass() == Date.class) {
                                            final DateBox dateBox = new DateBox();
                                            widget = dateBox;
                                            Runnable runnable = new Runnable() {
                                                public void run() {
                                                    Object propertyValue = itemDelegator.getEditableValue(
                                                            propertyDescriptor.getPropertyValue(object));
                                                    dateBox.setValue((Date) propertyValue);
                                                }
                                            };
                                            dateBox.addValueChangeHandler(new ValueChangeHandler<Date>() {
                                                public void onValueChange(ValueChangeEvent<Date> event) {
                                                    propertyDescriptor.setPropertyValue(object,
                                                            event.getValue());
                                                }
                                            });
                                            runnable.run();
                                            propertyUpdater.add(runnable);

                                        } else if (eDataType.getInstanceClass() == Boolean.class
                                                || eDataType.getInstanceClass() == boolean.class) {
                                            final CheckBox checkBox = new CheckBox();
                                            widget = checkBox;
                                            Runnable runnable = new Runnable() {
                                                public void run() {
                                                    Object propertyValue = itemDelegator.getEditableValue(
                                                            propertyDescriptor.getPropertyValue(object));
                                                    checkBox.setValue(Boolean.TRUE.equals(propertyValue));
                                                }
                                            };
                                            checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                                                public void onValueChange(ValueChangeEvent<Boolean> event) {
                                                    propertyDescriptor.setPropertyValue(object,
                                                            event.getValue());
                                                }
                                            });
                                            runnable.run();
                                            propertyUpdater.add(runnable);
                                        } else if (propertyDescriptor.isMultiLine(object)) {
                                            final TextArea textArea = new TextArea();
                                            widget = textArea;
                                            Runnable runnable = new Runnable() {
                                                public void run() {
                                                    Object propertyValue = itemDelegator.getEditableValue(
                                                            propertyDescriptor.getPropertyValue(object));
                                                    textArea.setText(EcoreUtil.convertToString(eDataType,
                                                            propertyValue));
                                                }
                                            };
                                            textArea.addValueChangeHandler(new ValueChangeHandler<String>() {
                                                public void onValueChange(ValueChangeEvent<String> event) {
                                                    propertyDescriptor.setPropertyValue(object, EcoreUtil
                                                            .createFromString(eDataType, event.getValue()));
                                                }
                                            });
                                            runnable.run();
                                            propertyUpdater.add(runnable);
                                        } else {
                                            final TextBox textBox = new TextBox();
                                            widget = textBox;
                                            textBox.addValueChangeHandler(new ValueChangeHandler<String>() {
                                                public void onValueChange(ValueChangeEvent<String> event) {
                                                    String value = event.getValue();
                                                    propertyDescriptor.setPropertyValue(object,
                                                            EcoreUtil.createFromString(eDataType, value));
                                                    // TOD0
                                                    // commandStack.execute(SetCommand.create(editingDomain, object, feature, EcoreUtil.createFromString(eDataType, value)));
                                                }
                                            });
                                            Runnable runnable = new Runnable() {
                                                public void run() {
                                                    Object propertyValue = itemDelegator.getEditableValue(
                                                            propertyDescriptor.getPropertyValue(object));
                                                    String stringValue = EcoreUtil.convertToString(eDataType,
                                                            propertyValue);
                                                    if (!textBox.getText().equals(stringValue)) {
                                                        textBox.setText(stringValue);
                                                    }
                                                }
                                            };
                                            runnable.run();
                                            propertyUpdater.add(runnable);
                                        }
                                    }
                                }
                            }
                        } else {
                            final TextBox textBox = new TextBox();
                            widget = textBox;
                            textBox.addValueChangeHandler(new ValueChangeHandler<String>() {
                                public void onValueChange(ValueChangeEvent<String> event) {
                                    String value = event.getValue();
                                    propertyDescriptor.setPropertyValue(object, value);
                                }
                            });
                            Runnable runnable = new Runnable() {
                                public void run() {
                                    Object propertyValue = itemDelegator
                                            .getEditableValue(propertyDescriptor.getPropertyValue(object));
                                    String stringValue = propertyValue == null ? null
                                            : propertyDescriptor.getLabelProvider(object)
                                                    .getText(propertyValue);
                                    if (!textBox.getText().equals(stringValue)) {
                                        textBox.setText(stringValue);
                                    }
                                }
                            };
                            runnable.run();
                            propertyUpdater.add(runnable);
                        }
                        if (widget != null) {
                            widget.setWidth("95%");
                            properties.setWidget(i, 1, widget);
                            if (!propertyDescriptor.canSetProperty(object) && widget instanceof FocusWidget) {
                                ((FocusWidget) widget).setEnabled(false);

                            }
                        }
                    }
                }
            }
        }
    });

    contentPanel.addWest(treeScrollPanel, 400);
    contentPanel.add(propertiesPanel);

    bodyPanel.addNorth(toolBar, 28.0);
    bodyPanel.add(contentPanel);

    RootPanel.get("main").add(mainPanel);

    createButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            Object selection = treeSelection.getSelectedObject();
            if (selection instanceof ResourceSet) {
                final DialogBox dialogBox = new DialogBox();
                dialogBox.setText("Create Resource");
                final Button okButton = new Button("OK");
                final Button cancelButton = new Button("Cancel");
                VerticalPanel verticalPanel = new VerticalPanel();
                Grid grid = new Grid();
                grid.setWidth("50em");
                grid.resize(3, 2);
                grid.getColumnFormatter().setWidth(0, "15%");
                grid.getColumnFormatter().setWidth(1, "85%");
                Label uriLabel = new Label();
                uriLabel.setText("URI");
                final TextBox uriText = new TextBox();
                uriText.setWidth("90%");
                int count = 1;
                while (resourceSet.getResource(URI.createURI("datastore:/resource" + count), false) != null) {
                    ++count;
                }
                uriText.setValue("datastore:/resource" + count);
                uriText.selectAll();
                final Label message = new Label();
                uriText.addValueChangeHandler(new ValueChangeHandler<String>() {
                    public void onValueChange(ValueChangeEvent<String> event) {
                        String value = event.getValue();
                        try {
                            if (resourceSet.getResource(URI.createURI(value), false) != null) {
                                message.setText("This URI a duplicate");
                                okButton.setEnabled(false);
                            } else {
                                message.setText("");
                                okButton.setEnabled(true);
                            }
                        } catch (RuntimeException exception) {
                            message.setText("This URI is not a well formed");
                            okButton.setEnabled(false);
                        }
                    }
                });
                grid.setWidget(0, 0, uriLabel);
                grid.setWidget(0, 1, uriText);
                verticalPanel.add(grid);
                grid.setWidget(1, 1, message);
                grid.setWidget(2, 0, okButton);
                grid.setWidget(2, 1, cancelButton);
                dialogBox.setWidget(verticalPanel);
                dialogBox.show();
                uriText.setFocus(true);
                // dialogBox.setWidth("50em");
                okButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        dialogBox.hide();
                        commandStack.execute(new AbstractCommand() {
                            Collection<?> affectedObjects;
                            Resource resource;

                            @Override
                            protected boolean prepare() {
                                return true;
                            }

                            public void redo() {
                                resourceSet.getResources().add(resource);
                                affectedObjects = Collections.singleton(resource);
                            }

                            @Override
                            public void undo() {
                                resourceSet.getResources().remove(resource);
                                affectedObjects = Collections.singleton(resourceSet);
                            }

                            public void execute() {
                                resource = resourceSet.createResource(URI.createURI(uriText.getValue()));
                                resource.getContents().clear();
                                affectedObjects = Collections.singleton(resource);
                            }

                            @Override
                            public Collection<?> getAffectedObjects() {
                                return affectedObjects;
                            }
                        });
                    }
                });
                cancelButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        dialogBox.hide();
                    }
                });
            } else if (selection instanceof Resource) {
                final Resource resource = (Resource) selection;
                final DialogBox dialogBox = new DialogBox();
                dialogBox.setText("Create Object");
                final ListBox listBox = new ListBox();
                listBox.setVisibleItemCount(1);
                Registry packageRegistry = resourceSet.getPackageRegistry();
                for (String nsURI : packageRegistry.keySet()) {
                    EPackage ePackage = packageRegistry.getEPackage(nsURI);
                    for (EClassifier eClassifier : ePackage.getEClassifiers()) {
                        if (eClassifier instanceof EClass) {
                            EClass eClass = (EClass) eClassifier;
                            if (!eClass.isAbstract()) {
                                EObject eObject = EcoreUtil.create(eClass);
                                listBox.addItem("New " + itemDelegator.getText(eObject),
                                        EcoreUtil.getURI(eClass).toString());
                            }
                        }
                    }
                }
                final Button okButton = new Button("OK");
                final Button cancelButton = new Button("Cancel");
                VerticalPanel verticalPanel = new VerticalPanel();
                Grid grid = new Grid();
                grid.setWidth("50em");
                grid.resize(2, 2);
                grid.getColumnFormatter().setWidth(0, "15%");
                grid.getColumnFormatter().setWidth(1, "85%");
                Label classLabel = new Label();
                classLabel.setText("Class");
                grid.setWidget(0, 0, classLabel);
                grid.setWidget(0, 1, listBox);
                verticalPanel.add(grid);
                // verticalPanel.add(okButton);
                grid.setWidget(1, 0, okButton);
                grid.setWidget(1, 1, cancelButton);
                dialogBox.setWidget(verticalPanel);
                dialogBox.show();
                listBox.setFocus(true);
                // dialogBox.setWidth("50em");
                okButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        dialogBox.hide();
                        commandStack.execute(new AbstractCommand() {
                            EObject eObject;
                            Collection<?> affectedObjects;

                            @Override
                            protected boolean prepare() {
                                return true;
                            }

                            public void redo() {
                                resource.getContents().add(eObject);
                                affectedObjects = Collections.singleton(eObject);
                            }

                            @Override
                            public void undo() {
                                resource.getContents().remove(eObject);
                                affectedObjects = Collections.singleton(resource);
                            }

                            public void execute() {
                                eObject = EcoreUtil.create((EClass) resourceSet.getEObject(
                                        URI.createURI(listBox.getValue(listBox.getSelectedIndex())), false));
                                resource.getContents().add(eObject);
                                affectedObjects = Collections.singleton(eObject);
                            }

                            @Override
                            public Collection<?> getAffectedObjects() {
                                return affectedObjects;
                            }
                        });
                    }
                });
                cancelButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        dialogBox.hide();
                    }
                });

            } else {
                Collection<?> newChildDescriptors = editingDomain.getNewChildDescriptors(selection, null);
                final DialogBox dialogBox = new DialogBox();
                dialogBox.setText("Create Object");
                final ListBox listBox = new ListBox();
                final List<Command> commands = new ArrayList<Command>();
                listBox.setVisibleItemCount(1);
                for (Object descriptor : newChildDescriptors) {
                    Command command = CreateChildCommand.create(editingDomain, selection, descriptor,
                            Collections.singleton(selection));
                    commands.add(command);
                    listBox.addItem(command.getLabel());
                }
                final Button okButton = new Button("OK");
                final Button cancelButton = new Button("Cancel");
                VerticalPanel verticalPanel = new VerticalPanel();
                Grid grid = new Grid();
                grid.setWidth("50em");
                grid.resize(2, 2);
                grid.getColumnFormatter().setWidth(0, "15%");
                grid.getColumnFormatter().setWidth(1, "85%");
                Label classLabel = new Label();
                classLabel.setText("Class");
                grid.setWidget(0, 0, classLabel);
                grid.setWidget(0, 1, listBox);
                verticalPanel.add(grid);
                // verticalPanel.add(okButton);
                grid.setWidget(1, 0, okButton);
                grid.setWidget(1, 1, cancelButton);
                dialogBox.setWidget(verticalPanel);
                dialogBox.show();
                listBox.setFocus(true);
                // dialogBox.setWidth("50em");
                okButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        dialogBox.hide();
                        commandStack.execute(commands.get(listBox.getSelectedIndex()));
                    }
                });
                cancelButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        dialogBox.hide();
                    }
                });
            }
        }
    });

    saveButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            EList<Resource> resources = resourceSet.getResources();
            for (Resource resource : resources) {
                try {
                    if (resource.isLoaded()) {
                        Map<String, Object> options = null;
                        if (originalResources.contains(resource)) {
                            options = new HashMap<String, Object>();
                            options.put(URIConverter.OPTION_UPDATE_ONLY_IF_TIME_STAMP_MATCHES,
                                    resource.getTimeStamp());
                        }
                        resource.save(options, new Callback<Resource>() {
                            public void onFailure(Throwable caught) {
                                final DialogBox dialogBox = new DialogBox();
                                dialogBox.setText("Save conflict");
                                final Button okButton = new Button("OK");
                                final Tree tree = new Tree();
                                tree.addItem(SafeHtmlUtils.fromString(caught.getLocalizedMessage()));
                                Grid grid = new Grid();
                                grid.setWidth("150em");
                                grid.resize(2, 1);
                                grid.setWidget(0, 0, tree);
                                grid.setWidget(1, 0, okButton);
                                dialogBox.setWidget(grid);
                                dialogBox.show();
                                okButton.addClickHandler(new ClickHandler() {
                                    public void onClick(ClickEvent event) {
                                        dialogBox.hide();
                                    }
                                });
                            }

                            public void onSuccess(Resource result) {
                                // TODO Auto-generated method stub
                            }
                        });
                    }
                } catch (IOException exception) {
                    EMFEditUIPlugin.INSTANCE.log(exception);
                }
            }
            for (Resource resource : originalResources) {
                if (!resources.contains(resource)) {
                    Map<String, Object> options = null;
                    if (resource.isLoaded()) {
                        options = new HashMap<String, Object>();
                        options.put(URIConverter.OPTION_UPDATE_ONLY_IF_TIME_STAMP_MATCHES,
                                resource.getTimeStamp());
                    }
                    resourceSet.getURIConverter().delete(resource.getURI(), options, new Callback<Map<?, ?>>() {
                        public void onFailure(Throwable caught) {
                            final DialogBox dialogBox = new DialogBox();
                            dialogBox.setText("Delete conflict");
                            final Button okButton = new Button("OK");
                            final Tree tree = new Tree();
                            tree.addItem(SafeHtmlUtils.fromString(caught.getLocalizedMessage()));
                            Grid grid = new Grid();
                            grid.setWidth("150em");
                            grid.resize(2, 1);
                            grid.setWidget(0, 0, tree);
                            grid.setWidget(1, 0, okButton);
                            dialogBox.setWidget(grid);
                            dialogBox.show();
                            okButton.addClickHandler(new ClickHandler() {
                                public void onClick(ClickEvent event) {
                                    dialogBox.hide();
                                }
                            });
                        }

                        public void onSuccess(Map<?, ?> result) {
                            // TODO Auto-generated method stub
                        }
                    });
                }
            }
            originalResources.clear();
            originalResources.addAll(resources);
            commandStack.saveIsDone();
            saveButton.setEnabled(false);
        }
    });

    validateButton.addClickHandler(new ClickHandler() {
        protected TreeItem createTreeItems(Diagnostic diagnostic) {
            TreeItem treeItem = new TreeItem(SafeHtmlUtils.fromString(diagnostic.getMessage()));
            List<?> data = diagnostic.getData();
            if (!data.isEmpty()) {
                treeItem.setUserObject(data.get(0));
            }
            for (Diagnostic child : diagnostic.getChildren()) {
                treeItem.addItem(createTreeItems(child));
            }
            return treeItem;
        }

        public void onClick(ClickEvent event) {
            Diagnostician diagnostician = new Diagnostician() {
                @Override
                public String getObjectLabel(EObject eObject) {
                    return !eObject.eIsProxy() ? itemDelegator.getText(eObject) : super.getObjectLabel(eObject);
                }
            };
            Map<Object, Object> context = diagnostician.createDefaultContext();
            EList<Resource> resources = resourceSet.getResources();
            BasicDiagnostic diagnostics = new BasicDiagnostic();
            for (Resource resource : resources) {
                if (resource.isLoaded()) {
                    for (EObject eObject : resource.getContents()) {
                        diagnostician.validate(eObject, diagnostics, context);
                    }
                }
            }
            final DialogBox dialogBox = new DialogBox();
            dialogBox.setText("Problems");
            final Button okButton = new Button("OK");
            final Tree tree = new Tree();
            if (diagnostics.getSeverity() == Diagnostic.OK) {
                tree.addItem(SafeHtmlUtils.fromString("No problems detected"));
            } else {
                for (Diagnostic child : diagnostics.getChildren()) {
                    tree.addItem(createTreeItems(child));
                }
            }
            Grid grid = new Grid();
            grid.setWidth("150em");
            grid.resize(2, 1);
            grid.setWidget(0, 0, tree);
            grid.setWidget(1, 0, okButton);
            dialogBox.setWidget(grid);
            dialogBox.show();
            okButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    TreeItem treeItem = tree.getSelectedItem();
                    if (treeItem != null) {
                        Object newSelection = treeItem.getUserObject();
                        if (newSelection != null) {
                            cellTree.expand(editingDomain.getTreePath(editingDomain.getParent(newSelection)));
                            treeSelection.setSelected(newSelection, true);
                        }
                    }
                    dialogBox.hide();
                }
            });
        }
    });
    saveButton.setEnabled(false);
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    commandStack.addCommandStackListener(new CommandStackListener() {
        public void commandStackChanged(EventObject event) {
            saveButton.setEnabled(commandStack.isSaveNeeded());
            undoButton.setEnabled(commandStack.canUndo());
            redoButton.setEnabled(commandStack.canRedo());

            Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand();
            if (mostRecentCommand != null) {
                Collection<?> affectedObjects = mostRecentCommand.getAffectedObjects();
                if (!affectedObjects.isEmpty()) {
                    Object newSelection = affectedObjects.iterator().next();
                    cellTree.expand(editingDomain.getTreePath(editingDomain.getParent(newSelection)));
                    if (treeSelection.getSelectedObject() == newSelection) {
                        for (Runnable runnable : propertyUpdater) {
                            runnable.run();
                        }
                    } else {
                        treeSelection.setSelected(newSelection, true);
                    }
                }
            }
        }
    });

    undoButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            commandStack.undo();
        }
    });

    redoButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            commandStack.redo();
        }
    });
}

From source file:org.eclipse.emf.eef.runtime.ui.gwt.editor.part.EEFPropertiesPanel.java

License:Open Source License

public void updateProperties(final Object newSelection) {
    if (oldSelection == newSelection) {
        for (Runnable runnable : propertyUpdater) {
            runnable.run();//from  ww w  . jav  a  2 s .  c om
        }
    } else {
        editor.getNavigationManager().setSelection(null);

        oldSelection = newSelection;

        List<IItemPropertyDescriptor> propertyDescriptors = editor.getItemDelegator()
                .getPropertyDescriptors(newSelection);
        if (propertyDescriptors != null) {
            properties.clear();
            propertyUpdater.clear();
            int size = propertyDescriptors.size();
            properties.resize(size, 2);
            properties.getColumnFormatter().setWidth(0, "10%");
            properties.getColumnFormatter().setWidth(1, "90%");
            for (int i = 0; i < size; ++i) {
                final IItemPropertyDescriptor propertyDescriptor = propertyDescriptors.get(i);
                properties.setText(i, 0, propertyDescriptor.getDisplayName(newSelection));
                Widget widget = null;
                final IItemLabelProvider itemLabelProvider = propertyDescriptor.getLabelProvider(newSelection);
                final Object feature = propertyDescriptor.getFeature(newSelection);
                if (feature instanceof EReference[]) {
                    final ItemPropertyDescriptorFeatureEditor dialog = new ItemPropertyDescriptorFeatureEditor(
                            newSelection, true, propertyDescriptor) {
                        @Override
                        protected void hook(ListBox listBox, List<?> values) {
                            editor.getNavigationManager().listenTo(listBox, values);
                        }
                    };
                    dialog.update();
                    widget = dialog;
                    propertyUpdater.add(new Runnable() {
                        public void run() {
                            dialog.update();
                        }
                    });
                } else if (feature instanceof EStructuralFeature) {
                    final EStructuralFeature eStructureFeature = (EStructuralFeature) feature;
                    final EClassifier eType = eStructureFeature.getEType();
                    final Collection<?> choiceOfValues = propertyDescriptor.getChoiceOfValues(newSelection);
                    if (choiceOfValues != null) {
                        final List<?> listOfValues = new ArrayList<Object>(
                                propertyDescriptor.getChoiceOfValues(newSelection));
                        if (propertyDescriptor.isMany(newSelection)) {
                            boolean valid = true;
                            for (Object choice : choiceOfValues) {
                                if (!eType.isInstance(choice)) {
                                    valid = false;
                                    break;
                                }
                            }

                            if (valid) {
                                final ItemPropertyDescriptorFeatureEditor dialog = new ItemPropertyDescriptorFeatureEditor(
                                        newSelection, true, propertyDescriptor) {
                                    @Override
                                    protected void hook(ListBox listBox, List<?> values) {
                                        editor.getNavigationManager().listenTo(listBox, values);
                                    }
                                };
                                dialog.update();
                                widget = dialog;
                                propertyUpdater.add(new Runnable() {
                                    public void run() {
                                        dialog.update();
                                    }
                                });
                            }
                        }
                        if (widget == null) {
                            final ListBox listBox = new ListBox();
                            widget = listBox;
                            listBox.setVisibleItemCount(1);
                            Runnable runnable = new Runnable() {
                                public void run() {
                                    listBox.clear();
                                    editor.getNavigationManager().listenTo(listBox, listOfValues);
                                    Object propertyValue = editor.getItemDelegator().getEditableValue(
                                            propertyDescriptor.getPropertyValue(newSelection));
                                    for (Object value : choiceOfValues) {
                                        listBox.addItem(itemLabelProvider.getText(value));
                                        if (value == null ? propertyValue == null
                                                : value.equals(propertyValue)) {
                                            listBox.setSelectedIndex(listBox.getItemCount() - 1);
                                        }
                                    }
                                }
                            };
                            listBox.addChangeHandler(new ChangeHandler() {
                                public void onChange(ChangeEvent event) {
                                    Object value = listOfValues.get(listBox.getSelectedIndex());
                                    propertyDescriptor.setPropertyValue(newSelection, value);
                                }
                            });
                            runnable.run();
                            propertyUpdater.add(runnable);
                        }
                    } else if (eType instanceof EDataType) {
                        final EDataType eDataType = (EDataType) eType;
                        if (eDataType.isSerializable()) {
                            if (propertyDescriptor.isMany(newSelection)) {
                                final ItemPropertyDescriptorFeatureEditor dialog = new ItemPropertyDescriptorFeatureEditor(
                                        newSelection, propertyDescriptor) {
                                    @Override
                                    protected void hook(ListBox listBox, List<?> values) {
                                        editor.getNavigationManager().listenTo(listBox, values);
                                    }
                                };
                                dialog.update();
                                widget = dialog;
                                propertyUpdater.add(new Runnable() {
                                    public void run() {
                                        dialog.update();
                                    }
                                });
                            } else {
                                if (eDataType.getInstanceClass() == Date.class) {
                                    final DateBox dateBox = new DateBox();
                                    widget = dateBox;
                                    Runnable runnable = new Runnable() {
                                        public void run() {
                                            Object propertyValue = editor.getItemDelegator().getEditableValue(
                                                    propertyDescriptor.getPropertyValue(newSelection));
                                            dateBox.setValue((Date) propertyValue);
                                        }
                                    };
                                    dateBox.addValueChangeHandler(new ValueChangeHandler<Date>() {
                                        public void onValueChange(ValueChangeEvent<Date> event) {
                                            propertyDescriptor.setPropertyValue(newSelection, event.getValue());
                                        }
                                    });
                                    runnable.run();
                                    propertyUpdater.add(runnable);

                                } else if (eDataType.getInstanceClass() == Boolean.class
                                        || eDataType.getInstanceClass() == boolean.class) {
                                    final CheckBox checkBox = new CheckBox();
                                    widget = checkBox;
                                    Runnable runnable = new Runnable() {
                                        public void run() {
                                            Object propertyValue = editor.getItemDelegator().getEditableValue(
                                                    propertyDescriptor.getPropertyValue(newSelection));
                                            checkBox.setValue(Boolean.TRUE.equals(propertyValue));
                                        }
                                    };
                                    checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
                                        public void onValueChange(ValueChangeEvent<Boolean> event) {
                                            propertyDescriptor.setPropertyValue(newSelection, event.getValue());
                                        }
                                    });
                                    runnable.run();
                                    propertyUpdater.add(runnable);
                                } else if (propertyDescriptor.isMultiLine(newSelection)) {
                                    final TextArea textArea = new TextArea();
                                    widget = textArea;
                                    Runnable runnable = new Runnable() {
                                        public void run() {
                                            Object propertyValue = editor.getItemDelegator().getEditableValue(
                                                    propertyDescriptor.getPropertyValue(newSelection));
                                            textArea.setText(
                                                    EcoreUtil.convertToString(eDataType, propertyValue));
                                        }
                                    };
                                    textArea.addValueChangeHandler(new ValueChangeHandler<String>() {
                                        public void onValueChange(ValueChangeEvent<String> event) {
                                            propertyDescriptor.setPropertyValue(newSelection,
                                                    EcoreUtil.createFromString(eDataType, event.getValue()));
                                        }
                                    });
                                    runnable.run();
                                    propertyUpdater.add(runnable);
                                } else {
                                    final TextBox textBox = new TextBox();
                                    widget = textBox;
                                    textBox.addValueChangeHandler(new ValueChangeHandler<String>() {
                                        public void onValueChange(ValueChangeEvent<String> event) {
                                            String value = event.getValue();
                                            propertyDescriptor.setPropertyValue(newSelection,
                                                    EcoreUtil.createFromString(eDataType, value));
                                            // TOD0
                                            // commandStack.execute(SetCommand.create(editingDomain,
                                            // object, feature,
                                            // EcoreUtil.createFromString(eDataType,
                                            // value)));
                                        }
                                    });
                                    Runnable runnable = new Runnable() {
                                        public void run() {
                                            Object propertyValue = editor.getItemDelegator().getEditableValue(
                                                    propertyDescriptor.getPropertyValue(newSelection));
                                            String stringValue = EcoreUtil.convertToString(eDataType,
                                                    propertyValue);
                                            if (!textBox.getText().equals(stringValue)) {
                                                textBox.setText(stringValue);
                                            }
                                        }
                                    };
                                    runnable.run();
                                    propertyUpdater.add(runnable);
                                }
                            }
                        }
                    }
                } else {
                    final TextBox textBox = new TextBox();
                    widget = textBox;
                    textBox.addValueChangeHandler(new ValueChangeHandler<String>() {
                        public void onValueChange(ValueChangeEvent<String> event) {
                            String value = event.getValue();
                            propertyDescriptor.setPropertyValue(newSelection, value);
                        }
                    });
                    Runnable runnable = new Runnable() {
                        public void run() {
                            Object propertyValue = editor.getItemDelegator()
                                    .getEditableValue(propertyDescriptor.getPropertyValue(newSelection));
                            String stringValue = propertyValue == null ? null
                                    : propertyDescriptor.getLabelProvider(newSelection).getText(propertyValue);
                            if (!textBox.getText().equals(stringValue)) {
                                textBox.setText(stringValue);
                            }
                        }
                    };
                    runnable.run();
                    propertyUpdater.add(runnable);
                }
                if (widget != null) {
                    widget.setWidth("95%");
                    properties.setWidget(i, 1, widget);
                    if (!propertyDescriptor.canSetProperty(newSelection) && widget instanceof FocusWidget) {
                        ((FocusWidget) widget).setEnabled(false);

                    }
                }
            }
        }
    }
}

From source file:org.ednovo.gooru.client.mvp.gsearch.SearchAbstractView.java

License:Open Source License

/**
 * @param filterPanel instance of DisclosurePanelUc which gets added widget
 * @param key check box name/*from  w w w . j av  a 2s  . co  m*/
 * @param value check box value
 */
public void renderCheckBox(PPanel filterPanel, String key, final String value) {
    final CheckBox categoryChk = new CheckBox();
    categoryChk.setText(value);
    categoryChk.setName(key);
    categoryChk.setStyleName("checkbox");
    //categoryChk.addStyleName(value.toLowerCase());
    filterPanel.add(categoryChk);
    if (value.equalsIgnoreCase("Mobile Friendly")) {
        final Image mobilefriendly = new Image();
        mobilefriendly.setUrl("images/mos/questionmark.png");
        mobilefriendly.getElement().getStyle().setCursor(Cursor.POINTER);
        mobilefriendly.setAltText(i18n.GL0732());
        mobilefriendly.setTitle(i18n.GL0732());
        mobilefriendly.addMouseOverHandler(new MouseOverHandler() {
            @Override
            public void onMouseOver(MouseOverEvent event) {
                toolTip = new ToolTip(i18n.GL0454() + "" + " " + i18n.GL04431() + " " + " ");
                toolTip.getTootltipContent().getElement().setAttribute("style", "width: 258px;");
                toolTip.getElement().getStyle().setBackgroundColor("transparent");
                toolTip.getElement().getStyle().setPosition(Position.ABSOLUTE);
                toolTip.setPopupPosition(mobilefriendly.getAbsoluteLeft() - (50 + 22),
                        mobilefriendly.getAbsoluteTop() + 22);
                toolTip.show();
            }
        });
        mobilefriendly.addMouseOutHandler(new MouseOutHandler() {
            @Override
            public void onMouseOut(MouseOutEvent event) {
                EventTarget target = event.getRelatedTarget();
                if (Element.is(target)) {
                    if (!toolTip.getElement().isOrHasChild(Element.as(target))) {
                        toolTip.hide();
                    }
                }
            }
        });
        filterPanel.add(mobilefriendly);
        categoryChk.getElement().setAttribute("style", "display: inline-block;");
    }
    categoryChk.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            callSearch();
        }
    });

}

From source file:org.ednovo.gooru.client.mvp.search.SearchFilterVc.java

License:Open Source License

/**
 * @param disclosurePanelVc instance of DisclosurePanelUc which gets added widget
 * @param key check box name/*from  w  w  w.  j  a v  a  2 s . com*/
 * @param value check box value
 */
public void renderCheckBox(DisclosurePanelUc disclosurePanelVc, String key, String value) {
    CheckBox categoryChk = new CheckBox();
    categoryChk.setText(value);
    categoryChk.setName(key);
    if (value.equalsIgnoreCase("videos")) {
        MixpanelUtil.mixpanelEvent("search_video_filter_selected");
        categoryChk.getElement().setId("chkVideos");
    } else if (value.equalsIgnoreCase("webpage")) {
        MixpanelUtil.mixpanelEvent("search_webpage_filter_selected");
        categoryChk.getElement().setId("chkwebpage");
    }
    /*else if(value.equalsIgnoreCase("websites"))
    {
       MixpanelUtil.mixpanelEvent("search_websites_filter_selected");
       categoryChk.getElement().setId("chkwebsites");   
    }*/
    else if (value.equalsIgnoreCase("interactives")) {
        MixpanelUtil.mixpanelEvent("search_interactives_filter_selected");
        categoryChk.getElement().setId("chkInteractives");
    } else if (value.equalsIgnoreCase("questions")) {
        MixpanelUtil.mixpanelEvent("search_questions_filter_selected");
        categoryChk.getElement().setId("chkQuestions");
    } else if (value.equalsIgnoreCase("images")) {
        MixpanelUtil.mixpanelEvent("search_images_filter_selected");
        categoryChk.getElement().setId("chkImages");
    } else if (value.equalsIgnoreCase("texts")) {
        MixpanelUtil.mixpanelEvent("search_texts_filter_selected");
        categoryChk.getElement().setId("chkTexts");
    } else if (value.equalsIgnoreCase("audios")) {
        MixpanelUtil.mixpanelEvent("search_audios_filter_selected");
        categoryChk.getElement().setId("chkAudios");
    }
    /*else if(value.equalsIgnoreCase("others")){
       MixpanelUtil.mixpanelEvent("search_others_filter_selected");
       categoryChk.getElement().setId("chkOther");
    }*/
    else if (value.equalsIgnoreCase("science")) {
        categoryChk.getElement().setId("chkScience");
    } else if (value.equalsIgnoreCase("math")) {
        categoryChk.getElement().setId("chkMath");
    } else if (value.equalsIgnoreCase("Social Sciences")) {
        categoryChk.getElement().setId("chkSocialSciences");
    } else if (value.equalsIgnoreCase("Language Arts")) {
        categoryChk.getElement().setId("chkLanguageArts");
    } else if (value.equalsIgnoreCase("Arts and Humanities")) {
        categoryChk.getElement().setId("chkArts&Humanities");
    } else if (value.equalsIgnoreCase("Technology and Engineering")) {
        categoryChk.getElement().setId("chkTechnology&Engineering");
    } else if (value.equalsIgnoreCase("Elementary School")) {
        categoryChk.getElement().setId("chkElementarySchool");
    } else if (value.equalsIgnoreCase("Middle School")) {
        categoryChk.getElement().setId("chkMiddleSchool");
    } else if (value.equalsIgnoreCase("High School")) {
        categoryChk.getElement().setId("chkHighSchool");
    } else if (value.equalsIgnoreCase("Higher Education")) {
        categoryChk.getElement().setId("chkHigherEducation");
    } else if (value.equalsIgnoreCase("Show only Quizzes")) {
        categoryChk.getElement().setId("chkShowonlyQuizzes");
    }
    categoryChk.setStyleName(CssTokens.FILTER_CHECKBOX);
    categoryChk.addStyleName(value.toLowerCase());
    disclosurePanelVc.addWidget(categoryChk);
    categoryChk.addValueChangeHandler(new ValueChangeHandler<Boolean>() {

        @Override
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            AppClientFactory.fireEvent(new GetSearchKeyWordEvent());
        }
    });
}

From source file:org.freemedsoftware.gwt.client.screen.CallInScreen.java

License:Open Source License

protected void initSearchPopup() {
    if (searchDialogBox == null) {
        searchDialogBox = new CustomDialogBox();
        FlexTable flexTable = new FlexTable();

        int row = 0;

        final Label firstLastNameLabel = new Label(_("Name (Last, First)") + ":");
        flexTable.setWidget(row, 0, firstLastNameLabel);
        final TextBox lastName = new TextBox();
        flexTable.setWidget(row, 1, lastName);
        final TextBox firstName = new TextBox();
        flexTable.setWidget(row, 2, firstName);

        row++;//from  ww  w  .  j  a v a  2s. com

        final Label fullNameLabel = new Label(_("Call-In Patient") + ":");
        flexTable.setWidget(row, 0, fullNameLabel);
        final SupportModuleWidget fullName = new SupportModuleWidget("Callin");
        flexTable.setWidget(row, 1, fullName);

        final CheckBox showArchived = new CheckBox(_("Include Archived") + ":");
        flexTable.setWidget(row, 2, showArchived);
        showArchived.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                if (event.getValue()) {
                    HashMap<String, String> args = new HashMap<String, String>();
                    args.put("ciarchive", "1");
                    fullName.setAdditionalParameters(args);
                } else
                    fullName.setAdditionalParameters(null);
            }
        });

        row++;

        final CustomButton searchBTN = new CustomButton(_("Search"), AppConstants.ICON_SEARCH);
        flexTable.setWidget(row, 1, searchBTN);
        searchCriteria = null;
        searchBTN.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                searchCriteria = new HashMap<String, String>();
                if (lastName.getText().trim().length() > 0)
                    searchCriteria.put("cilname", lastName.getText());
                if (firstName.getText().trim().length() > 0)
                    searchCriteria.put("cifname", firstName.getText());
                if (fullName.getValue() > 0)
                    searchCriteria.put("id", fullName.getValue().toString());
                if (showArchived.getValue())
                    searchCriteria.put("ciarchive", showArchived.getValue() ? "1" : "0");
                populate(searchCriteria);

                searchDialogBox.hide();
            }

        });

        searchDialogBox.setContent(flexTable);
    }
    searchDialogBox.show();
    searchDialogBox.center();

}