Example usage for org.eclipse.jface.viewers StructuredSelection EMPTY

List of usage examples for org.eclipse.jface.viewers StructuredSelection EMPTY

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection EMPTY.

Prototype

StructuredSelection EMPTY

To view the source code for org.eclipse.jface.viewers StructuredSelection EMPTY.

Click Source Link

Document

The canonical empty selection.

Usage

From source file:eu.aniketos.wp1.ststool.diagram.part.StsToolNewDiagramFileWizard.java

License:Open Source License

/**
 * @generated//from   w ww .  jav a  2  s.c o  m
 */
public StsToolNewDiagramFileWizard(URI domainModelURI, EObject diagramRoot,
        TransactionalEditingDomain editingDomain) {
    assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$
    assert diagramRoot != null : "Doagram root element must be specified"; //$NON-NLS-1$
    assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$

    myFileCreationPage = new WizardNewFileCreationPage(Messages.StsToolNewDiagramFileWizard_CreationPageName,
            StructuredSelection.EMPTY);
    myFileCreationPage.setTitle(Messages.StsToolNewDiagramFileWizard_CreationPageTitle);
    myFileCreationPage.setDescription(NLS.bind(Messages.StsToolNewDiagramFileWizard_CreationPageDescription,
            StsToolDiagramEditPart.MODEL_ID));
    IPath filePath;
    String fileName = URI.decode(domainModelURI.trimFileExtension().lastSegment());
    if (domainModelURI.isPlatformResource()) {
        filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true));
    } else if (domainModelURI.isFile()) {
        filePath = new Path(domainModelURI.trimSegments(1).toFileString());
    } else {
        // TODO : use some default path
        throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); //$NON-NLS-1$
    }
    myFileCreationPage.setContainerFullPath(filePath);
    myFileCreationPage
            .setFileName(StsToolDiagramEditorUtil.getUniqueFileName(filePath, fileName, "ststool_diagram")); //$NON-NLS-1$

    diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(
            Messages.StsToolNewDiagramFileWizard_RootSelectionPageName);
    diagramRootElementSelectionPage.setTitle(Messages.StsToolNewDiagramFileWizard_RootSelectionPageTitle);
    diagramRootElementSelectionPage
            .setDescription(Messages.StsToolNewDiagramFileWizard_RootSelectionPageDescription);
    diagramRootElementSelectionPage.setModelElement(diagramRoot);

    myEditingDomain = editingDomain;
}

From source file:eu.aniketos.wp1.ststool.report.wizard.NodeCheckboxTreeViewer.java

License:Open Source License

public NodeCheckboxTreeViewer(Composite parent) {

    checkboxTreeViewer = new CheckboxTreeViewer(parent, SWT.BORDER);

    checkboxTreeViewer.setContentProvider(new TreeProvider());
    checkboxTreeViewer.setLabelProvider(new TreeProvider());
    checkboxTreeViewer.setCheckStateProvider(new TreeProvider());

    checkboxTreeViewer.expandAll();/*from w w w . ja v a  2 s  . c  om*/

    checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            Node n = (Node) event.getElement();
            boolean checked = event.getChecked();
            if (!n.isModificable()) {
                event.getCheckable().setChecked(n, !checked);
                return;
            } else {
                n.setCheked(checked);
                for (Node ch : n.getChildren()) {
                    ch.setCheked(checked);
                }
                checkboxTreeViewer.setSubtreeChecked(event.getElement(), checked);

                if (n.getParent() != null) {
                    checkboxTreeViewer.setChecked(n.getParent(), true);
                    n.getParent().setCheked(true);
                }
            }

        }
    });
    checkboxTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection s = (IStructuredSelection) event.getSelection();
            if (s.getFirstElement() != null && !((Node) s.getFirstElement()).isModificable())
                checkboxTreeViewer.setSelection(StructuredSelection.EMPTY);
        }
    });

}

From source file:eu.artist.premigration.tft.tft.dialog.MigrationStrategySelectionDialog.java

License:Open Source License

/**
 * Creates the dialog area /*w  w  w  .  ja va2s. co  m*/
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(3, false);
    container.setLayout(layout);

    Label infoLabel = new Label(container, SWT.NONE);
    infoLabel.setText(
            "Add migration strategies to this component from the leftmost panel or remove already suggested/selected strategies from the");
    infoLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));

    Label infoLabel2 = new Label(container, SWT.NONE);
    infoLabel2.setText("rightmost panel.");
    infoLabel2.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));

    Label emptyLabel = new Label(container, SWT.NONE);
    emptyLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1));

    //Collect suggested strategy ids
    List<String> suggestedStrategIDs = new ArrayList<String>();
    for (MigrationStrategy strategy : selectedComponent.getMigrationStrategies()) {
        suggestedStrategIDs.add(strategy.getId());
    }

    //Create labels
    Label leftLabel = new Label(container, SWT.NONE);
    leftLabel.setText("Available Migration Strategies");
    leftLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));

    Label rightLabel = new Label(container, SWT.NONE);
    rightLabel.setText("Selected Migration Strategies");
    rightLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    //Creation of the tree viewer for available strategies
    createTreeViewerForAvailableStrategies(container);

    //Creation of Add button
    Composite buttonGroup = new Composite(container, SWT.NONE);
    buttonGroup.setLayout(new GridLayout(1, false));

    final Button addButton = new Button(buttonGroup, SWT.PUSH);
    addButton.setEnabled(false);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    addButton.setText("Add");

    //Creation of the remove button
    final Button removeButton = new Button(buttonGroup, SWT.PUSH);
    removeButton.setEnabled(false);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    removeButton.setText("Remove");

    //Creation of the tree viewer for selected strategies
    createTreeViewerForSelectedStrategies(container);

    //Definition of description label
    //final Label descriptionLabel = new Label(container, SWT.NONE);
    final Text description = new Text(container, SWT.MULTI | SWT.WRAP);
    description.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 5));

    //Selection changed listener for Available Strategies Tree
    availableStrategiesTree.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof ChildStrategy) {
                ChildStrategy selectedStrategy = (ChildStrategy) selection.getFirstElement();
                //Removing the selection on Selected Strategies Tree
                selectedStrategiesTree.setSelection(StructuredSelection.EMPTY);
                //Selecting the parent category of the selected strategy on the Selected Strategies Tree to know where to add the strategy
                for (TreeItem item : selectedStrategiesTree.getTree().getItems()) {
                    ParentCategory parent = (ParentCategory) item.getData();
                    if (parent.getCategory().equals(selectedStrategy.getParent().getCategory())) {
                        selectedStrategiesTree.setSelection(new StructuredSelection(parent));
                    }
                }
                //Add button is enabled
                addButton.setEnabled(true);

                //Print the description
                String descriptionText = selectedStrategy.getStrategy().getDescription();
                description.setText(
                        (descriptionText != null && !descriptionText.trim().equals("")) ? descriptionText
                                : "No description available yet.");
            } else {
                //If there is no selection or the selected item is not a strategy (may be a category) the add button is disabled.
                addButton.setEnabled(false);
                description.setText("");
            }
        }
    });

    //Selection changed listener for Selected Strategies Tree
    selectedStrategiesTree.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof ChildStrategy) {

                ChildStrategy selectedStrategy = (ChildStrategy) selection.getFirstElement();
                //Removing the selection on Available Strategies Tree
                availableStrategiesTree.setSelection(StructuredSelection.EMPTY);
                //Selecting the parent category of the selected strategy on the Available Strategies Tree to know where to move the removed strategy
                for (TreeItem item : availableStrategiesTree.getTree().getItems()) {
                    ParentCategory parent = (ParentCategory) item.getData();
                    if (parent.getCategory().equals(selectedStrategy.getParent().getCategory())) {
                        availableStrategiesTree.setSelection(new StructuredSelection(parent));
                    }
                }
                //Remove button is enabled
                removeButton.setEnabled(true);

                //Print the description
                String descriptionText = selectedStrategy.getStrategy().getDescription();
                description.setText(
                        (descriptionText != null && !descriptionText.trim().equals("")) ? descriptionText
                                : "No description available yet.");
            } else {
                //If there is no selection or the selected item is not a strategy (may be a category) the remove button is disabled.
                removeButton.setEnabled(false);
                description.setText("");
            }
        }
    });

    //Registering the selection listeners
    addButton.addSelectionListener(
            new SelectionAdapterForTreeModification(availableStrategiesTree, selectedStrategiesTree, false));
    removeButton.addSelectionListener(
            new SelectionAdapterForTreeModification(selectedStrategiesTree, availableStrategiesTree, true));

    return container;
}

From source file:eu.esdihumboldt.hale.ui.function.common.PropertyEntitySelector.java

License:Open Source License

/**
 * Set the parent type// www.ja va 2  s.  co  m
 * 
 * @param parentType the parentType to set
 */
public void setParentType(TypeEntityDefinition parentType) {
    // reset candidates?? refresh viewer?
    if (!Objects.equal(this.parentType, parentType)) {
        this.parentType = parentType;
        // reset selection if necessary
        EntityDefinition selection = getSelectedObject();
        if (selection != null && parentType != null) {
            // maybe also keep selection, if it is a super/sub type of
            // parentType, which also got the selected property?
            if (!AlignmentUtil.getTypeEntity(selection).equals(parentType)) {
                setSelection(StructuredSelection.EMPTY);
            }
        }
    }
}

From source file:eu.esdihumboldt.hale.ui.function.common.SourceTargetTypeSelector.java

License:Open Source License

/**
 * Creates a new selector.//from w  ww.  j  a v a2 s. c o m
 * 
 * @param parent the parent composite
 */
public SourceTargetTypeSelector(Composite parent) {
    main = new Composite(parent, SWT.NONE);
    main.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            functionLabels.dispose();
        }
    });
    main.setLayout(new GridLayout(4, false));

    ISelectionChangedListener listener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (!inUpdate)
                fireSelectionChanged();
        }
    };

    GridDataFactory selectorgd = GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT);

    sourceTypeSelector = new TypeEntitySelector(SchemaSpaceID.SOURCE, null, main, false);
    selectorgd.applyTo(sourceTypeSelector.getControl());
    sourceTypeSelector.addSelectionChangedListener(listener);

    selectCellButton = new Button(main, SWT.PUSH);
    selectCellButton.setText("Select cell");
    selectCellButton.setToolTipText("Select a type cell");
    selectCellButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TypeCellSelectionDialog dialog = new TypeCellSelectionDialog(main.getShell().getShell(),
                    "Select a type cell", selectedCell);
            if (dialog.open() == TypeCellSelectionDialog.OK) {
                Cell selected = dialog.getObject();
                inUpdate = true;
                setSelection(selected);
                inUpdate = false;
                fireSelectionChanged();
            }
        }
    });

    Button resetSelectionButton = new Button(main, SWT.PUSH);
    resetSelectionButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            setSelection(StructuredSelection.EMPTY);
        }
    });
    final Image resetSelectionImage = HALEUIPlugin.getImageDescriptor("icons/remove.gif").createImage();
    resetSelectionButton.setImage(resetSelectionImage);
    resetSelectionButton.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            resetSelectionImage.dispose();
        }
    });
    resetSelectionButton.setToolTipText("Reset selection");

    targetTypeSelector = new TypeEntitySelector(SchemaSpaceID.TARGET, null, main, false);
    selectorgd.applyTo(targetTypeSelector.getControl());
    targetTypeSelector.addSelectionChangedListener(listener);
}

From source file:eu.esdihumboldt.hale.ui.function.common.SourceTargetTypeSelector.java

License:Open Source License

/**
 * Sets the selected type entity definitions.<br>
 * If an existing cell was selected, that selection is undone.
 * //w w  w  .j av a  2  s. c o m
 * @param type the type to select, may be <code>null</code>
 * @param ssid the schema space to set the type to (needed because type may
 *            be null)
 */
public void setSelection(TypeEntityDefinition type, SchemaSpaceID ssid) {
    inUpdate = true;
    // undo cell selection
    setSelection((Cell) null);

    ISelection selection = (type == null) ? StructuredSelection.EMPTY : new StructuredSelection(type);
    if (ssid == SchemaSpaceID.SOURCE)
        sourceTypeSelector.setSelection(selection);
    else if (ssid == SchemaSpaceID.TARGET)
        targetTypeSelector.setSelection(selection);
    inUpdate = false;
    fireSelectionChanged();
}

From source file:eu.esdihumboldt.hale.ui.function.common.SourceTargetTypeSelector.java

License:Open Source License

/**
 * Sets the selection according to the given cell.<br>
 * If the cell is a property cell, it will select the types whom the
 * properties belong to.<br>/*from   w ww . j av a 2  s.  c o m*/
 * If <code>cell</code> is <code>null</code> the selected types aren't
 * changed, but is an existing type cell was selected, that selection is
 * undone.
 * 
 * @param cell the cell to set the selection to
 */
private void setSelection(Cell cell) {
    if (cell != null) {
        // in case of a real join cell there are multiple source types
        if (cell.getSource() == null || cell.getSource().isEmpty())
            sourceTypeSelector.setSelection(StructuredSelection.EMPTY);
        else if (cell.getSource().size() > 1)
            sourceTypeSelector.showText("<multiple types>");
        else {
            Entity source = CellUtil.getFirstEntity(cell.getSource());
            ISelection selection = new StructuredSelection(AlignmentUtil.getTypeEntity(source.getDefinition()));
            sourceTypeSelector.setSelection(selection);
        }
        // target can only be one or none
        Entity target = CellUtil.getFirstEntity(cell.getTarget());
        ISelection selection = (target == null) ? StructuredSelection.EMPTY
                : new StructuredSelection(AlignmentUtil.getTypeEntity(target.getDefinition()));
        targetTypeSelector.setSelection(selection);
    }

    if (cell != null && AlignmentUtil.isTypeCell(cell) && cell.getId() != null) {
        // a real type cell
        selectedCell = cell;

        String label;
        String functionId = cell.getTransformationIdentifier();
        AbstractFunction<?> function = FunctionUtil.getFunction(functionId);
        if (function != null)
            label = functionLabels.getText(function);
        else
            label = functionId;
        selectCellButton.setText(label);

        sourceTypeSelector.getControl().setEnabled(false);
        targetTypeSelector.getControl().setEnabled(false);
    } else {
        selectedCell = null;

        selectCellButton.setText("Select cell");

        sourceTypeSelector.getControl().setEnabled(true);
        targetTypeSelector.getControl().setEnabled(true);
    }
}

From source file:eu.esdihumboldt.hale.ui.functions.custom.pages.internal.BindingOrTypeEditor.java

License:Open Source License

@Override
public void setValue(BindingOrType value) {
    if (value.isUseBinding()) {
        bindingSelect.setSelection(new StructuredSelection(possibleBindingForClass(value.getBinding())));
    } else {/*w  ww  . ja  va 2s .  c o m*/
        bindingSelect.setSelection(new StructuredSelection(PossibleBindings.NONE));
    }
    if (value.getType() != null) {
        typeSelect.setSelection(new StructuredSelection(value.getType()));
    } else {
        typeSelect.setSelection(StructuredSelection.EMPTY);
    }
}

From source file:eu.esdihumboldt.hale.ui.functions.groovy.internal.TypeStructureTray.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);

    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);

    // retrieve the types
    final Collection<? extends TypeDefinition> types = this.types.getTypes();

    // heading//from   w  ww  .  java 2 s  .  c om
    Label caption = new Label(page, SWT.NONE);
    switch (schemaSpace) {
    case SOURCE:
        caption.setText("Source structure");
        break;
    case TARGET:
        caption.setText("Target structure");
        break;
    }
    caption.setFont(JFaceResources.getHeaderFont());

    // create tree viewer
    PatternFilter patternFilter = new SchemaPatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    final FilteredTree filteredTree = new TreePathFilteredTree(page,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);

    TreeViewer tree = filteredTree.getViewer();
    tree.setUseHashlookup(true);
    StyledDefinitionLabelProvider labelProvider = new StyledDefinitionLabelProvider();
    tree.setLabelProvider(labelProvider);
    IContentProvider contentProvider;
    if (types.size() == 1) {
        contentProvider = new TreePathProviderAdapter(new TypePropertyContentProvider(tree));
    } else {
        contentProvider = new TreePathProviderAdapter(new TypeDefinitionContentProvider(tree));
    }
    tree.setContentProvider(contentProvider);
    GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);

    tree.setComparator(new DefinitionComparator());

    // set input
    if (types.size() == 1) {
        tree.setInput(types.iterator().next());
    } else {
        tree.setInput(types);
    }

    /*
     * Groovy specific part
     */

    // caption
    Label example = new Label(page, SWT.NONE);
    switch (schemaSpace) {
    case SOURCE:
        example.setText("Examples: Access variables");
        break;
    case TARGET:
        example.setText("Example: Build instance");
        break;
    default:
        example.setText("Example");
    }

    // source viewer
    final SourceViewer viewer = new SourceViewer(page, null,
            SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);

    final IColorManager colorManager = new GroovyColorManager();
    SourceViewerConfiguration configuration = new SimpleGroovySourceViewerConfiguration(colorManager,
            ImmutableList.of(BINDING_TARGET, BINDING_BUILDER, BINDING_INDEX, BINDING_SOURCE,
                    BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT,
                    BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT),
            null);
    viewer.configure(configuration);

    GridDataFactory.fillDefaults().grab(true, false).hint(200, 130).applyTo(viewer.getControl());

    // make sure the color manager is disposed
    viewer.getControl().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            colorManager.dispose();
        }
    });

    // react to tree selection changes
    tree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IDocument doc = new Document();
            GroovySourceViewerUtil.setupDocument(doc);
            String example = null;
            if (!event.getSelection().isEmpty()) {
                switch (schemaSpace) {
                case SOURCE:
                    example = createSourceSample(event.getSelection(), types);
                    break;
                case TARGET:
                    example = createTargetSample(event.getSelection(), types);
                    break;
                }
            }

            if (example == null || example.isEmpty()) {
                switch (schemaSpace) {
                case SOURCE:
                    doc.set("// Please select schema elements to access");
                    break;
                case TARGET:
                    doc.set("// Please select which schema elements\n// to include in the instance to build");
                    break;
                default:
                    doc.set("// Please select one or more schema elements");
                }
            } else {
                doc.set(example);
            }

            viewer.setDocument(doc);
        }
    });

    tree.setSelection(StructuredSelection.EMPTY);

    return page;
}

From source file:eu.esdihumboldt.hale.ui.service.instance.sample.internal.InstanceViewPreferencePage.java

License:Open Source License

@Override
protected void performDefaults() {
    super.performDefaults();

    // update the enabled button with the default
    enabled.setSelection(InstanceViewPreferences.ENABLED_DEFAULT);

    // update the settings map with default values
    for (Entry<String, Sampler> entry : InstanceViewPreferences.SAMPLERS.entrySet()) {
        samplerSettings.put(entry.getKey(), entry.getValue().getDefaultSettings());
    }/*  w  w w  .  ja v  a2  s.c o m*/

    // update the current editor
    if (currentEditor != null) {
        // set the editor value
        currentEditor
                .setValue(samplerSettings.get(InstanceViewPreferences.SAMPLERS.inverse().get(currentSampler)));
    }

    // select the default sampler
    Sampler selectedSampler = InstanceViewPreferences.SAMPLERS.get(InstanceViewPreferences.SAMPLER_FIRST);
    if (selectedSampler != null) {
        samplers.setSelection(new StructuredSelection(selectedSampler));
    } else {
        samplers.setSelection(StructuredSelection.EMPTY);
    }

    changed = true;

    // update the occurring values button with the default
    occurringValuesComplete.setSelection(InstanceViewPreferences.OCCURRING_VALUES_EXTERNAL_DEFAULT);

    ov_changed = true;
}