summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2013-05-05 16:01:07 (EDT)
committerJuergen Haug2013-05-05 16:01:07 (EDT)
commit9eab08530e398cf70bc9e3dccc3c6607fae7e5f1 (patch)
tree79a426fb68762a4d14d24c3be0edc3e9b4e45282
parent72d62b85fd7827cf9613bfde265324fb565870ba (diff)
downloadorg.eclipse.etrice-9eab08530e398cf70bc9e3dccc3c6607fae7e5f1.zip
org.eclipse.etrice-9eab08530e398cf70bc9e3dccc3c6607fae7e5f1.tar.gz
org.eclipse.etrice-9eab08530e398cf70bc9e3dccc3c6607fae7e5f1.tar.bz2
[ui] added diagram update on super class changerefs/changes/19/12519/1
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java20
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java97
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/SuperClassListener.java183
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java7
4 files changed, 306 insertions, 1 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
index 47a16eb..88bc538 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java
@@ -23,11 +23,16 @@ import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.RoomFactory;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
+import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.etrice.ui.behavior.Activator;
import org.eclipse.etrice.ui.behavior.support.ContextSwitcher;
import org.eclipse.etrice.ui.behavior.support.SupportUtil;
import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
+import org.eclipse.graphiti.dt.IDiagramTypeProvider;
+import org.eclipse.graphiti.features.IFeatureProvider;
+import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
@@ -196,4 +201,19 @@ public class BehaviorEditor extends RoomDiagramEditor {
parent.getSubgraph().getStates().add(rs);
}
}
+
+ @Override
+ protected void superClassChanged() {
+ IDiagramTypeProvider diagramTypeProvider = getDiagramTypeProvider();
+ Diagram diagram = diagramTypeProvider.getDiagram();
+ IFeatureProvider featureProvider = diagramTypeProvider.getFeatureProvider();
+ IUpdateContext updateCtx = new UpdateContext(diagram);
+ featureProvider.updateIfPossible(updateCtx);
+ refresh();
+ }
+
+ @Override
+ protected StructureClass getStructureClass() {
+ return getActorClass();
+ }
}
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java
index de41865..3f2285f 100644
--- a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java
@@ -14,25 +14,33 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature.Setting;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.ui.RoomUiModule;
+import org.eclipse.etrice.core.ui.editor.RoomEditor;
import org.eclipse.etrice.ui.common.Activator;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.serializer.ISerializer;
import org.eclipse.xtext.util.CancelIndicator;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;
@@ -46,13 +54,15 @@ import com.google.inject.Injector;
* @author Henrik Rentz-Reichert initial contribution and API
*
*/
-public class RoomDiagramEditor extends DiagramEditor {
+public abstract class RoomDiagramEditor extends DiagramEditor {
@Inject
protected IResourceValidator resourceValidator;
private SaveOnFocusLostListener partListener;
+ private SuperClassListener superClassListener;
+
private ModificationTrackingEnabler mte = new ModificationTrackingEnabler();
public RoomDiagramEditor() {
@@ -81,6 +91,8 @@ public class RoomDiagramEditor extends DiagramEditor {
mte.unsetTarget(getEditingDomain());
getSite().getPage().removePartListener(partListener);
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().removePartListener(superClassListener);
+ superClassListener.dispose();
super.dispose();
}
@@ -149,6 +161,9 @@ public class RoomDiagramEditor extends DiagramEditor {
partListener = new SaveOnFocusLostListener(this);
getSite().getPage().addPartListener(partListener);
+ superClassListener = new SuperClassListener(this);
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().addPartListener(superClassListener);
+
/* we have to save here whether changes have been done or not to get rid of the dirty state
* CAUTION: save in
* init(IEditorSite site, IEditorInput input)
@@ -170,7 +185,87 @@ public class RoomDiagramEditor extends DiagramEditor {
// inside this call auto refresh will happen iff (and turn the editor dirty)
super.setFocus();
+ if(superClassListener.isChangeInSuperClass())
+ superClassChanged();
+
if (!dirtyAlready && isDirty())
doSave(null);
}
+
+ /**
+ * Check whether the given diagram editor manages a super class
+ * @param editor
+ * @return
+ */
+ protected boolean registerSuperClassListener(RoomDiagramEditor editor) {
+ if(!(this.getClass().equals(editor.getClass()) && this.getStructureClass() instanceof ActorClass))
+ return false;
+
+ StructureClass editorSc = editor.getStructureClass();
+ if(editorSc instanceof ActorClass){
+ URI editorResURI = toCurrentPlatformURI(editorSc.eResource().getURI());
+
+ ActorClass base = (ActorClass) getStructureClass();
+ while((base = base.getBase()) != null){
+ URI baseResURI = toCurrentPlatformURI(base.eResource().getURI());
+ if(editorResURI.equals(baseResURI))
+ if(editorSc.getName().equals(base.getName()))
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Check whether the given room editor has a super class
+ * @param editor
+ * @return
+ */
+ protected boolean registerSuperClassListener(RoomEditor editor) {
+ if(!(this.getStructureClass() instanceof ActorClass))
+ return false;
+
+ return editor.getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>(){
+
+ @Override
+ public Boolean exec(XtextResource resource) throws Exception {
+
+ URI editorResURI = toCurrentPlatformURI(resource.getURI());
+ URI thisScResURI = toCurrentPlatformURI(getStructureClass().eResource().getURI());
+
+ // ignore if in same file (handled by graphiti)
+ if(thisScResURI.equals(editorResURI))
+ return false;
+
+ ActorClass base = (ActorClass) getStructureClass();
+ while((base = base.getBase()) != null){
+ URI baseResURI = toCurrentPlatformURI(base.eResource().getURI());
+ if(editorResURI.equals(baseResURI))
+ return true;
+ }
+
+ return false;
+ }
+ });
+ }
+
+ private URI toCurrentPlatformURI(URI uri){
+ if(uri.isPlatform())
+ return uri;
+ else if(uri.isFile()){
+ final IPath rootPath = ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ String rootString = rootPath.toFile().toString();
+ String fileString = uri.toFileString();
+ if(fileString.startsWith(rootString))
+ return URI.createPlatformResourceURI(fileString.replace(rootString, ""), false);
+ }
+ return null;
+ }
+
+ protected abstract void superClassChanged();
+
+ protected abstract StructureClass getStructureClass();
+
}
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/SuperClassListener.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/SuperClassListener.java
new file mode 100644
index 0000000..04d37cd
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/SuperClassListener.java
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * Copyright (c) 2012 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.common.editor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.ResourceSetChangeEvent;
+import org.eclipse.emf.transaction.ResourceSetListener;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.etrice.core.ui.editor.RoomEditor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.editor.model.IXtextModelListener;
+
+public class SuperClassListener implements IPartListener, ResourceSetListener, IXtextModelListener {
+
+ private RoomDiagramEditor diagramEditor;
+ private List<TransactionalEditingDomain> domains;
+ private List<IXtextDocument> xtextDocuments;
+ private boolean changeInSuperClass;
+
+ public SuperClassListener(RoomDiagramEditor diagramEditor) {
+ this.diagramEditor = diagramEditor;
+ domains = new ArrayList<TransactionalEditingDomain>();
+ xtextDocuments = new ArrayList<IXtextDocument>();
+ changeInSuperClass = false;
+ }
+
+ public boolean isChangeInSuperClass() {
+ return changeInSuperClass;
+ }
+
+ public void dispose(){
+ for(TransactionalEditingDomain domain : domains){
+ if(domain != null)
+ domain.removeResourceSetListener(this);
+ }
+ for(IXtextDocument document : xtextDocuments){
+ if(document != null)
+ document.removeModelListener(this);
+ }
+ }
+
+ // ---
+ // IPartListener
+ // ---
+
+ @Override
+ public void partActivated(IWorkbenchPart part) {
+
+ }
+
+ @Override
+ public void partBroughtToTop(IWorkbenchPart part) {
+
+ }
+
+ @Override
+ public void partClosed(IWorkbenchPart part) {
+ if(part instanceof RoomDiagramEditor){
+ RoomDiagramEditor editor = (RoomDiagramEditor)part;
+ TransactionalEditingDomain toRemove = editor.getEditingDomain();
+ if(toRemove != null){
+ toRemove.removeResourceSetListener(this);
+ domains.remove(toRemove);
+ }
+ }
+
+ if(part instanceof RoomEditor){
+ IXtextDocument toRemove = ((RoomEditor) part).getDocument();
+ if(toRemove != null){
+ toRemove.removeModelListener(this);
+ xtextDocuments.remove(toRemove);
+ }
+ }
+ }
+
+ @Override
+ public void partDeactivated(IWorkbenchPart part) {
+ if(part == diagramEditor)
+ changeInSuperClass = false;
+ }
+
+ @Override
+ public void partOpened(IWorkbenchPart part) {
+ // initial
+ if(part==diagramEditor){
+ IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ for (IEditorReference editorRef : activePage.getEditorReferences()) {
+ IEditorPart editor = editorRef.getEditor(false);
+ if (editor != null && editor!=diagramEditor)
+ partOpened(editor);
+ }
+ return;
+ }
+
+ if(part instanceof RoomDiagramEditor){
+ RoomDiagramEditor editor = (RoomDiagramEditor)part;
+ TransactionalEditingDomain domain = editor.getEditingDomain();
+ if(!domains.contains(domain) && diagramEditor.registerSuperClassListener(editor)){
+ domain.addResourceSetListener(this);
+ domains.add(domain);
+ }
+ }
+
+ if(part instanceof RoomEditor){
+ RoomEditor editor = (RoomEditor) part;
+ IXtextDocument document = editor.getDocument();
+
+ if(!xtextDocuments.contains(document) && diagramEditor.registerSuperClassListener(editor)){
+ editor.getDocument().addModelListener(this);
+ xtextDocuments.add(document);
+ }
+ }
+ }
+
+ // ---
+ // ResourceSetListener
+ // ---
+
+ @Override
+ public NotificationFilter getFilter() {
+ return null;
+ }
+
+ @Override
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event)
+ throws RollbackException {
+ return null;
+ }
+
+ @Override
+ public void resourceSetChanged(ResourceSetChangeEvent event) {
+ // TODO: only set changed if resource is saved
+ changeInSuperClass = true;
+ }
+
+ @Override
+ public boolean isAggregatePrecommitListener() {
+ return false;
+ }
+
+ @Override
+ public boolean isPrecommitOnly() {
+ return false;
+ }
+
+ @Override
+ public boolean isPostcommitOnly() {
+ return true;
+ }
+
+ // ---
+ // IXtextModelListener
+ // ---
+
+ @Override
+ public void modelChanged(XtextResource resource) {
+ // TODO: only set changed if resource is saved
+ changeInSuperClass = true;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
index 8eddbc6..22d232f 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
@@ -37,6 +37,7 @@ public class StructureEditor extends RoomDiagramEditor {
/**
* @return the actor class of this editor
*/
+ @Override
public StructureClass getStructureClass() {
Diagram diagram = getDiagramTypeProvider().getDiagram();
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
@@ -45,5 +46,11 @@ public class StructureEditor extends RoomDiagramEditor {
return null;
}
+
+ @Override
+ protected void superClassChanged() {
+ // TODO Auto-generated method stub
+
+ }
}