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

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

Introduction

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

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:com.archimatetool.editor.propertysections.PropertiesLabelProviderTests.java

License:Open Source License

@Test
public void testGetTextRelation() {
    // Text for relation
    IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    String text = provider.getText(new StructuredSelection(relation));
    assertEquals("Assignment relation", text);

    // Text for DiagramModelArchimateConnection
    IDiagramModelArchimateConnection connection = IArchimateFactory.eINSTANCE
            .createDiagramModelArchimateConnection();
    connection.setArchimateRelationship(relation);
    text = provider.getText(new StructuredSelection(relation));
    assertEquals("Assignment relation", text);

    // Text for EditPart
    EditPart editPart = new ArchimateRelationshipEditPart(AssignmentConnectionFigure.class);
    editPart.setModel(connection);//from w  w w .  ja va 2s  . com
    text = provider.getText(new StructuredSelection(editPart));
    assertEquals("Assignment relation", text);
}

From source file:com.archimatetool.editor.propertysections.PropertiesLabelProviderTests.java

License:Open Source License

@Test
public void testGetTextDiagramModel() {
    // Text for diagram model
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    String text = provider.getText(new StructuredSelection(dm));
    assertEquals("View", text);

    // Text for EditPart
    ArchimateDiagramPart editPart = new ArchimateDiagramPart();
    editPart.setModel(dm);//from  w  w  w.  j  ava  2 s .c o m
    text = provider.getText(new StructuredSelection(editPart));
    assertEquals("View", text);
}

From source file:com.archimatetool.editor.propertysections.PropertiesLabelProviderTests.java

License:Open Source License

@Test
public void testGetTextNote() {
    // Text for diagram model
    IDiagramModelNote note = IArchimateFactory.eINSTANCE.createDiagramModelNote();
    String text = provider.getText(new StructuredSelection(note));
    assertEquals("Note", text);

    // Text for EditPart
    NoteEditPart editPart = new NoteEditPart();
    editPart.setModel(note);//from w w w . j av a  2  s  .  c  o  m
    text = provider.getText(new StructuredSelection(editPart));
    assertEquals("Note", text);
}

From source file:com.archimatetool.editor.propertysections.PropertiesLabelProviderTests.java

License:Open Source License

@Test
public void testGetAdaptable() {
    IAdaptable adaptable = new IAdaptable() {
        IArchimateElement element = IArchimateFactory.eINSTANCE.createArtifact();

        @SuppressWarnings({ "rawtypes", "unchecked" })
        public Object getAdapter(Class adapter) {
            if (adapter != null && (adapter.isInstance(element) || adapter.isInstance(this))) {
                return element;
            }/*from  ww  w.  j  av a 2s  .  c o m*/

            return null;
        }
    };

    String text = provider.getText(new StructuredSelection(adaptable));
    assertEquals("Artifact", text);

    Image image = provider.getImage(new StructuredSelection(adaptable));
    assertNotNull(image);
}

From source file:com.archimatetool.editor.propertysections.UsedInRelationshipsSection.java

License:Open Source License

private void createTableControl(Composite parent) {
    createLabel(parent, Messages.UsedInRelationshipsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH,
            SWT.NONE);//  www . j ava 2s . c om

    // Table
    Composite tableComp = createTableComposite(parent, SWT.NONE);
    fTableLayout = (UpdatingTableColumnLayout) tableComp.getLayout();
    fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION);

    // Column
    TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
    fTableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));

    // On Mac shows alternate table row colours
    fTableViewer.getTable().setLinesVisible(true);

    // Help ID
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);

    fTableViewer.setContentProvider(new IStructuredContentProvider() {
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }

        public Object[] getElements(Object inputElement) {
            return ArchimateModelUtils.getRelationships((IArchimateElement) inputElement).toArray();
        }
    });

    fTableViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            IRelationship relationship = (IRelationship) element;
            String name = ArchimateLabelProvider.INSTANCE.getLabel(relationship) + " ("; //$NON-NLS-1$
            name += ArchimateLabelProvider.INSTANCE.getLabel(relationship.getSource());
            name += " - "; //$NON-NLS-1$
            name += ArchimateLabelProvider.INSTANCE.getLabel(relationship.getTarget());
            name += ")"; //$NON-NLS-1$
            return name;
        }

        @Override
        public Image getImage(Object element) {
            return ArchimateLabelProvider.INSTANCE.getImage(element);
        }
    });

    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            if (isAlive()) {
                Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
                if (o instanceof IArchimateElement) {
                    IRelationship relation = (IRelationship) o;
                    ITreeModelView view = (ITreeModelView) ViewManager.findViewPart(ITreeModelView.ID);
                    if (view != null) {
                        view.getViewer().setSelection(new StructuredSelection(relation), true);
                    }
                }
            }
        }
    });

    fTableViewer.setSorter(new ViewerSorter());
}

From source file:com.archimatetool.editor.propertysections.ViewpointSection.java

License:Open Source License

protected void refreshControls() {
    int index = fDiagramModel.getViewpoint();
    IViewpoint viewPoint = ViewpointsManager.INSTANCE.getViewpoint(index);

    fIsRefreshing = true; // A Viewer will get a selectionChanged event when setting it
    fComboViewer.setSelection(new StructuredSelection(viewPoint));
    fIsRefreshing = false;//from w  ww  .j a v  a2 s  . com

    if (fIsShowing) {
        updateComponentSelection(viewPoint);
    }
}

From source file:com.archimatetool.editor.tools.GenerateViewDialog.java

License:Open Source License

void loadPreferences() {
    IPreferenceStore store = ArchiPlugin.INSTANCE.getPreferenceStore();

    fAddAllConnectionsButton.setSelection(store.getBoolean(PREFS_ALLCONNECTIONS));

    String id = store.getString(PREFS_LASTVIEWPOINT);
    IViewpoint lastViewpoint = ViewpointManager.INSTANCE.getViewpoint(id);

    if (!fValidViewPoints.contains(lastViewpoint)) {
        lastViewpoint = ViewpointManager.NONE_VIEWPOINT;
    }//  ww  w  .  j  av a 2  s.  c  o m

    fComboViewer.setSelection(new StructuredSelection(lastViewpoint));
}

From source file:com.archimatetool.editor.views.tree.commands.DeleteElementsCompoundCommand.java

License:Open Source License

@Override
public void execute() {
    super.execute();

    // Select object
    if (fObjectToSelect != null) {
        UIRequestManager.INSTANCE// w ww  . j  a  v a2 s .  c om
                .fireRequest(new TreeSelectionRequest(this, new StructuredSelection(fObjectToSelect), true));
    }
}

From source file:com.archimatetool.editor.views.tree.commands.DuplicateCommandHandler.java

License:Open Source License

/**
 * Perform the duplicate command//from   w  w  w.j  av  a 2s.  c  o m
 */
public void duplicate() {
    // Gather the elements to duplicate
    getElementsToDuplicate();

    // Create the Commands
    createCommands();

    // Execute the Commands on the CommandStack(s) - there could be more than one if more than one model open in the Tree
    for (Entry<CommandStack, CompoundCommand> entry : fCommandMap.entrySet()) {
        entry.getKey().execute(entry.getValue());
    }

    // Select new objects in Tree
    UIRequestManager.INSTANCE
            .fireRequest(new TreeSelectionRequest(this, new StructuredSelection(fNewObjects), true));

    dispose();
}

From source file:com.archimatetool.editor.views.tree.commands.NewDiagramCommand.java

License:Open Source License

@Override
public void undo() {
    // Close the Editor FIRST!
    EditorManager.closeDiagramEditor(fDiagramModel);

    fFolder.getElements().remove(fDiagramModel);

    // Select the parent node if no node is selected (this happens when the node is deleted)
    TreeSelectionRequest request = new TreeSelectionRequest(this, new StructuredSelection(fFolder), true) {
        @Override//from  w  w  w  .  j a v  a  2 s. c o  m
        public boolean shouldSelect(Viewer viewer) {
            return viewer.getSelection().isEmpty();
        }
    };
    UIRequestManager.INSTANCE.fireRequest(request);
}