Skip to content

Commit

Permalink
Select objects in a View with async part 3
Browse files Browse the repository at this point in the history
* We need to select objects with asyncExec if the EditorPart is closed
* So we can do that safely from the calling method.
* Add a safety measure in selectObjects() to check that the control is not null.

It can be the case that a EditorPart is not created when
1. TreeSelectionSync is on
2. There are diagram model ref objects in Views
3. The Views are open in the editor are but not created yet
4. A View is then closed
  • Loading branch information
Phillipus committed Jul 5, 2019
1 parent 5450324 commit 6a92328
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Expand Up @@ -906,6 +906,11 @@ protected void createActions(GraphicalViewer viewer) {

@Override
public void selectObjects(Object[] objects) {
// Safety check in case this is called via Display#asyncExec()
if(getGraphicalViewer().getControl() == null) {
return;
}

Set<Object> selection = new HashSet<>();

for(Object object : objects) {
Expand Down
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;

import com.archimatetool.editor.diagram.IArchimateDiagramEditor;
import com.archimatetool.editor.diagram.IDiagramModelEditor;
import com.archimatetool.editor.model.DiagramModelUtils;
import com.archimatetool.editor.ui.IArchiImages;
Expand Down Expand Up @@ -115,12 +114,14 @@ public void doubleClick(DoubleClickEvent event) {
if(!isAlive(fArchimateConcept)) {
return;
}
Object o = ((IStructuredSelection)event.getSelection()).getFirstElement();
if(o instanceof IDiagramModel) {
IDiagramModel diagramModel = (IDiagramModel)o;
IDiagramModel diagramModel = (IDiagramModel)((IStructuredSelection)event.getSelection()).getFirstElement();
if(diagramModel != null) {
IDiagramModelEditor editor = EditorManager.openDiagramEditor(diagramModel, false);
if(editor instanceof IArchimateDiagramEditor) {
((IArchimateDiagramEditor)editor).selectObjects(new Object[] { fArchimateConcept });
if(editor != null) {
// Needs to be asyncExec to allow EditorPart to open if it is currently closed
getPart().getSite().getShell().getDisplay().asyncExec(()-> {
editor.selectObjects(new Object[] { fArchimateConcept });
});
}
}
}
Expand Down
Expand Up @@ -49,7 +49,6 @@
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.archimatetool.editor.ArchiPlugin;
import com.archimatetool.editor.diagram.IArchimateDiagramEditor;
import com.archimatetool.editor.diagram.IDiagramModelEditor;
import com.archimatetool.editor.model.IEditorModelManager;
import com.archimatetool.editor.ui.ArchiLabelProvider;
Expand Down Expand Up @@ -335,8 +334,11 @@ else if(issue.getObject() instanceof IDiagramModelComponent) {
if(!viewList.isEmpty()) {
for(IDiagramModel dm : viewList) {
IDiagramModelEditor editor = EditorManager.openDiagramEditor(dm, false);
if(editor instanceof IArchimateDiagramEditor) {
((IArchimateDiagramEditor)editor).selectObjects(viewComponentList.toArray());
if(editor != null) {
// Needs to be asyncExec to allow EditorPart to open if it is currently closed
getSite().getShell().getDisplay().asyncExec(()-> {
editor.selectObjects(viewComponentList.toArray());
});
}
}
}
Expand Down

0 comments on commit 6a92328

Please sign in to comment.