/** * Given and edit part model, we want to expand the selection to * include all the edit parts that reference that model, as well * as query the edit part for additional selections */ @Override @SuppressWarnings("unchecked") public void appendSelection(EditPart ep) { super.appendSelection(ep); Set<Object> models = new LinkedHashSet<Object>(); models.add(ep.getModel()); SelectionManager selectionManager = getSelectionManager(); for (Object o : ((IStructuredSelection)selectionManager.getSelection()).toArray()) { models.add(((EditPart)o).getModel()); } Set<EditPart> editParts = new LinkedHashSet<EditPart>(getSelectableEditParts(models)); ISelection epSelection = CommonUtils.getAdapter(ep, ISelection.class); if (epSelection != null) { editParts.remove(ep); editParts.addAll(((IStructuredSelection)epSelection).toList()); } else { editParts.remove(ep); // move the primary selection to the end of the list editParts.add(ep); } selectionManager.setSelection(new StructuredSelection(editParts.toArray(new EditPart[0]))); }
/** * @see EditPartViewer#setSelectionManager(SelectionManager) */ public void setSelectionManager(SelectionManager model) { Assert.isNotNull(model); if (selectionModel != null) selectionModel.internalUninstall(); selectionModel = model; model.internalInitialize(this, selection, new Runnable() { public void run() { fireSelectionChanged(); } }); if (getControl() != null) model.internalHookControl(getControl()); }
private void setSelectedDefault() { final SelectionManager lSelectionManager = viewer.getSelectionManager(); if (model == null) { lSelectionManager.setSelection(StructuredSelection.EMPTY); } else { selectedObject = (ItemEditPart) viewer.getEditPartRegistry().get(model.getCenter()); lSelectionManager.setSelection(new StructuredSelection(selectedObject)); } }
@Override public void selectionChanged(final SelectionChangedEvent inEvent) { if (isSelectionChangeHandling()) { endSelectionChangeHandling(); return; } if (inEvent.getSelection().isEmpty()) { return; } // prevent multi selection by deselecting all selected items except // the last final SelectionManager lManager = viewer.getSelectionManager(); final Object[] lSelections = ((IStructuredSelection) inEvent.getSelection()).toArray(); for (int i = 0; i < lSelections.length - 1; i++) { if (lSelections[i] instanceof EditPart) { lManager.deselect((EditPart) lSelections[i]); } } final Object lSelection = lSelections[lSelections.length - 1]; if (lSelection instanceof ItemEditPart) { if (model != null) { selectedObject = (ItemEditPart) lSelection; eventBroker.post(RelationsConstants.TOPIC_TO_BROWSER_MANAGER_SET_SELECTED, new SelectedItemChangeEvent((ItemAdapter) selectedObject.getModel(), DefaultBrowserPart.this)); } } if (lSelection instanceof RelationEditPart) { eventBroker.post(RelationsConstants.TOPIC_TO_BROWSER_MANAGER_SET_SELECTED, ((RelationEditPart) lSelection).getModel()); } if (lSelection instanceof RelationsEditPart) { // this ensures that clicking the background doesn't deselect // the selected object lManager.setSelection(new StructuredSelection(selectedObject)); } }
@Override @SuppressWarnings("unchecked") public void doPropertyChange(PropertyChangeEvent event) { if ("consumed".equals(event.getPropagationId())) { return; } if (event.getPropertyName().equals(DiagramWalkerSet.PROPERTY_CHANGE_DIAGRAM_WALKER)) { refreshChildren(); } else if (event.getPropertyName().equals(ERVirtualDiagram.PROPERTY_CHANGE_VTABLES)) { refresh(); refreshRelations(); } else if (event.getPropertyName().equals(ERDiagram.PROPERTY_CHANGE_ALL)) { refresh(); refreshRelations(); final List<DiagramWalker> nodeElementList = (List<DiagramWalker>) event.getNewValue(); if (nodeElementList != null) { getViewer().deselectAll(); final SelectionManager selectionManager = getViewer().getSelectionManager(); final Map<DiagramWalker, EditPart> modelToEditPart = getModelToEditPart(); for (final DiagramWalker walker : nodeElementList) { selectionManager.appendSelection(modelToEditPart.get(walker)); } } } else if (event.getPropertyName().equals(ERDiagram.PROPERTY_CHANGE_ADD)) { final Object newValue = event.getNewValue(); if (newValue instanceof ERVirtualDiagram) { refresh(); refreshVisuals(); } } else if (event.getPropertyName().equals(ERDiagram.PROPERTY_CHANGE_TABLE)) { final TableView newTable = (TableView) event.getNewValue(); internalRefreshTable(newTable); } else if (event.getPropertyName().equals(ViewableModel.PROPERTY_CHANGE_COLOR)) { refreshVisuals(); } else if (event.getPropertyName().equals(ERDiagram.PROPERTY_CHANGE_DATABASE)) { changeDatabase(event); } else if (event.getPropertyName().equals(ERDiagramPropertySource.PROPERTY_INIT_DATABASE)) { final ERDiagram diagram = (ERDiagram) getModel(); diagram.restoreDatabase(DBManagerFactory.getAllDBList().get(0)); } else if (event.getPropertyName().equals(ERDiagram.PROPERTY_CHANGE_SETTINGS)) { changeSettings(); } }
/** * Constructs the viewer and calls {@link #init()}. */ public AbstractEditPartViewer() { setSelectionManager(SelectionManager.createDefault()); init(); }
/** * @see EditPartViewer#getSelectionManager() */ public SelectionManager getSelectionManager() { return selectionModel; }