Browse Source

Variables and Events are grouped by Interface Scopes in Declaratinos View

Andreas Mülder 14 years ago
parent
commit
9e53f36568

BIN
plugins/org.yakindu.sct.simulation.ui/icons/Scope.gif


+ 3 - 1
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/DeclarationImages.java

@@ -13,7 +13,9 @@ public enum DeclarationImages {
 
 	EVENT("icons/Event.gif"),
 
-	VARIABLE("icons/Variable.gif");
+	VARIABLE("icons/Variable.gif"),
+	
+	SCOPE("icons/Scope.gif");
 
 	private final String path;
 

+ 8 - 3
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/DeclarationView.java

@@ -15,10 +15,12 @@ import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.IDebugEventSetListener;
 import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.internal.ui.actions.CollapseAllAction;
 import org.eclipse.debug.ui.AbstractDebugView;
 import org.eclipse.debug.ui.DebugUITools;
 import org.eclipse.debug.ui.contexts.DebugContextEvent;
 import org.eclipse.debug.ui.contexts.IDebugContextListener;
+import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -30,6 +32,7 @@ import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.handlers.ExpandAllHandler;
 import org.yakindu.sct.simulation.core.debugmodel.SCTDebugTarget;
 import org.yakindu.sct.simulation.core.runtime.IExecutionContext;
 import org.yakindu.sct.simulation.core.runtime.IExecutionFacade;
@@ -94,7 +97,6 @@ public class DeclarationView extends AbstractDebugView implements
 				}
 			}
 		});
-
 		return viewer;
 	}
 
@@ -132,12 +134,15 @@ public class DeclarationView extends AbstractDebugView implements
 		IExecutionFacade facade = (IExecutionFacade) debugTarget
 				.getAdapter(IExecutionFacade.class);
 		viewer.setInput(facade.getExecutionContext());
+		viewer.expandAll();
 
 	}
 
 	@Override
 	protected void createActions() {
-
+		@SuppressWarnings("restriction")
+		IAction action = new CollapseAllAction(viewer);
+		setAction("CollapseAll",action); //$NON-NLS-1$
 	}
 
 	@Override
@@ -152,7 +157,7 @@ public class DeclarationView extends AbstractDebugView implements
 
 	@Override
 	protected void configureToolBar(IToolBarManager tbm) {
-
+		tbm.add(getAction("CollapseAll")); //$NON-NLS-1$
 	}
 
 }

+ 76 - 5
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ExecutionContextContentProvider.java

@@ -10,6 +10,9 @@
  */
 package org.yakindu.sct.simulation.ui.view;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.widgets.Display;
@@ -31,6 +34,41 @@ public class ExecutionContextContentProvider implements ITreeContentProvider,
 
 	private Viewer viewer;
 
+	public class Container {
+		public String name = "Default";
+		public List<AbstractSlot> slots = new ArrayList<AbstractSlot>();
+		@Override
+		public int hashCode() {
+			final int prime = 31;
+			int result = 1;
+			result = prime * result + getOuterType().hashCode();
+			result = prime * result + ((name == null) ? 0 : name.hashCode());
+			return result;
+		}
+		@Override
+		public boolean equals(Object obj) {
+			if (this == obj)
+				return true;
+			if (obj == null)
+				return false;
+			if (getClass() != obj.getClass())
+				return false;
+			Container other = (Container) obj;
+			if (!getOuterType().equals(other.getOuterType()))
+				return false;
+			if (name == null) {
+				if (other.name != null)
+					return false;
+			} else if (!name.equals(other.name))
+				return false;
+			return true;
+		}
+		private ExecutionContextContentProvider getOuterType() {
+			return ExecutionContextContentProvider.this;
+		}
+		
+	}
+
 	public void dispose() {
 
 	}
@@ -51,14 +89,45 @@ public class ExecutionContextContentProvider implements ITreeContentProvider,
 		if (inputElement == null) {
 			return new Object[] {};
 		}
-		IExecutionContext context = (IExecutionContext) inputElement;
-		Iterable<AbstractSlot> concat = Iterables.concat(
-				context.getDeclaredEvents(), context.getVariables());
-		return Iterables.toArray(concat, Object.class);
+		if (inputElement instanceof IExecutionContext) {
+			List<Container> scopes = new ArrayList<ExecutionContextContentProvider.Container>();
+			Container defaultContainer = new Container();
+			scopes.add(defaultContainer);
+			IExecutionContext context = (IExecutionContext) inputElement;
+			Iterable<AbstractSlot> concat = Iterables.concat(
+					context.getDeclaredEvents(), context.getVariables());
+			for (AbstractSlot abstractSlot : concat) {
+				String[] split = abstractSlot.getName().split("\\.");
+				if (split.length == 1) {
+					defaultContainer.slots.add(abstractSlot);
+				} else if (split.length == 2) {
+					boolean found = false;
+					for (Container container : scopes) {
+						if (split[0].equals(container.name)) {
+							container.slots.add(abstractSlot);
+							found = true;
+							break;
+						}
+					}
+					if (!found) {
+						Container newScope = new Container();
+						newScope.name = split[0];
+						newScope.slots.add(abstractSlot);
+						scopes.add(newScope);
+					}
+				}
+			}
+			return scopes.toArray();
+		}
+		return new Object[] {};
+
 	}
 
 	public Object[] getChildren(Object parentElement) {
-		return null;
+		if (parentElement instanceof Container) {
+			return ((Container) parentElement).slots.toArray();
+		}
+		return new Object[] {};
 	}
 
 	public Object getParent(Object element) {
@@ -66,6 +135,8 @@ public class ExecutionContextContentProvider implements ITreeContentProvider,
 	}
 
 	public boolean hasChildren(Object element) {
+		if (element instanceof Container)
+			return true;
 		return false;
 	}
 

+ 6 - 1
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ExecutionContextLabelProvider.java

@@ -18,6 +18,8 @@ import org.yakindu.sct.simulation.core.runtime.impl.AbstractSlot;
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionEvent;
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionVariable;
 import org.yakindu.sct.simulation.ui.DeclarationImages;
+import org.yakindu.sct.simulation.ui.view.ExecutionContextContentProvider.Container;
+
 /**
  * 
  * @author andreas muelder - Initial contribution and API
@@ -26,7 +28,7 @@ import org.yakindu.sct.simulation.ui.DeclarationImages;
 public class ExecutionContextLabelProvider extends StyledCellLabelProvider {
 
 	private final int index;
-	
+
 	public ExecutionContextLabelProvider(int index) {
 		this.index = index;
 	}
@@ -70,6 +72,9 @@ public class ExecutionContextLabelProvider extends StyledCellLabelProvider {
 			ExecutionVariable variable = (ExecutionVariable) element;
 			cell.setText(variable.getName());
 			cell.setImage(DeclarationImages.VARIABLE.image());
+		} else if (element instanceof Container) {
+			cell.setText(((Container) element).name);
+			cell.setImage(DeclarationImages.SCOPE.image());
 		}
 	}