Prechádzať zdrojové kódy

Added collapse all, expand all and hide time events action

Andreas Mülder 13 rokov pred
rodič
commit
fdf3508b2d

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


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


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

@@ -17,7 +17,11 @@ public enum DeclarationImages {
 
 	VARIABLE("icons/Variable.gif"),
 	
-	SCOPE("icons/Scope.gif");
+	SCOPE("icons/Scope.gif"),
+	
+	COLLAPSE_ALL("icons/collapseall.gif"),
+	
+	EXPAND_ALL("icons/expandall.gif");
 
 	private final String path;
 

+ 13 - 6
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/DeclarationView.java

@@ -15,7 +15,6 @@ 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;
@@ -36,6 +35,9 @@ import org.yakindu.sct.simulation.core.debugmodel.SCTDebugTarget;
 import org.yakindu.sct.simulation.core.runtime.IExecutionContext;
 import org.yakindu.sct.simulation.core.runtime.IExecutionFacade;
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionEvent;
+import org.yakindu.sct.simulation.ui.view.actions.CollapseAllAction;
+import org.yakindu.sct.simulation.ui.view.actions.ExpandAllAction;
+import org.yakindu.sct.simulation.ui.view.actions.HideTimeEventsAction;
 import org.yakindu.sct.simulation.ui.view.editing.BooleanEditingSupport;
 import org.yakindu.sct.simulation.ui.view.editing.IntegerEditingSupport;
 import org.yakindu.sct.simulation.ui.view.editing.MultiEditingSupport;
@@ -72,7 +74,7 @@ public class DeclarationView extends AbstractDebugView implements
 		TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.DEFAULT);
 		column.getColumn().setText("Name");
 		column.getColumn().setMoveable(true);
-		column.getColumn().setWidth(200);
+		column.getColumn().setWidth(150);
 		column.setLabelProvider(new ExecutionContextLabelProvider(0));
 
 		TreeViewerColumn valueColumn = new TreeViewerColumn(viewer, SWT.DEFAULT);
@@ -141,9 +143,12 @@ public class DeclarationView extends AbstractDebugView implements
 
 	@Override
 	protected void createActions() {
-		@SuppressWarnings("restriction")
-		IAction action = new CollapseAllAction(viewer);
-		setAction("CollapseAll", action); //$NON-NLS-1$
+		IAction collapse = new CollapseAllAction(viewer);
+		setAction("CollapseAll", collapse); 
+		IAction expand = new ExpandAllAction(viewer);
+		setAction("ExpandAll", expand); 
+		IAction hideTimeEvent = new HideTimeEventsAction(true);
+		setAction("HideTimeEvent", hideTimeEvent);
 	}
 
 	@Override
@@ -158,7 +163,9 @@ public class DeclarationView extends AbstractDebugView implements
 
 	@Override
 	protected void configureToolBar(IToolBarManager tbm) {
-		tbm.add(getAction("CollapseAll")); //$NON-NLS-1$
+		tbm.add(getAction("CollapseAll")); 
+		tbm.add(getAction("ExpandAll"));
+		tbm.add(getAction("HideTimeEvent")); 
 	}
 
 }

+ 99 - 60
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ExecutionContextContentProvider.java

@@ -11,8 +11,13 @@
 package org.yakindu.sct.simulation.ui.view;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.widgets.Display;
@@ -21,7 +26,10 @@ import org.yakindu.sct.simulation.core.runtime.IExecutionContextListener;
 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.SimulationActivator;
+import org.yakindu.sct.simulation.ui.view.actions.HideTimeEventsAction;
 
+import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 
 /**
@@ -30,50 +38,16 @@ import com.google.common.collect.Iterables;
  * 
  */
 public class ExecutionContextContentProvider implements ITreeContentProvider,
-		IExecutionContextListener {
+		IExecutionContextListener, IPropertyChangeListener {
 
 	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() {
+		getStore().removePropertyChangeListener(this);
+	}
 
+	public ExecutionContextContentProvider() {
+		getStore().addPropertyChangeListener(this);
 	}
 
 	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
@@ -93,41 +67,47 @@ public class ExecutionContextContentProvider implements ITreeContentProvider,
 			return new Object[] {};
 		}
 		if (inputElement instanceof IExecutionContext) {
-			List<Container> scopes = new ArrayList<ExecutionContextContentProvider.Container>();
+			Set<Container> scopes = new HashSet<Container>();
 			Container defaultContainer = new Container();
 			scopes.add(defaultContainer);
-			Container timeEventContainer = new Container();
-			timeEventContainer.name = "Time Events";
+			Container timeEventContainer = new Container("Time Events");
 			scopes.add(timeEventContainer);
 			IExecutionContext context = (IExecutionContext) inputElement;
-			Iterable<AbstractSlot> concat = Iterables.concat(
+			Iterable<AbstractSlot> slotelements = Iterables.concat(
 					context.getDeclaredEvents(), context.getVariables());
-			for (AbstractSlot abstractSlot : concat) {
-				String[] split = abstractSlot.getName().split("\\.");
-				if (split.length == 1) {
-					if (split[0].contains("time_event")) {
-						timeEventContainer.slots.add(abstractSlot);
+			for (AbstractSlot abstractSlot : slotelements) {
+				if (abstractSlot.getScopeSegment() != null) {
+					Container newScope = new Container();
+					newScope.name = abstractSlot.getScopeSegment();
+					newScope.slots.add(abstractSlot);
+					scopes.add(newScope);
+				}
+			}
+			for (AbstractSlot abstractSlot : slotelements) {
+				if (abstractSlot.getScopeSegment() == null) {
+					if (abstractSlot.getSimpleName().contains("time_event")) {
+						if (!hideTimeEvents()) {
+							timeEventContainer.slots.add(abstractSlot);
+						}
 					} else {
 						defaultContainer.slots.add(abstractSlot);
 					}
-				} else if (split.length == 2) {
-					boolean found = false;
+				} else {
 					for (Container container : scopes) {
-						if (split[0].equals(container.name)) {
+						if (abstractSlot.getScopeSegment().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 Iterables.toArray(
+					Iterables.filter(scopes, new Predicate<Container>() {
+						public boolean apply(Container input) {
+							return input.slots.size() > 0;
+						}
+					}), Container.class);
 		}
 		return new Object[] {};
 
@@ -156,9 +136,68 @@ public class ExecutionContextContentProvider implements ITreeContentProvider,
 	public void variableValueChanged(ExecutionVariable variable) {
 		Display.getDefault().asyncExec(new Runnable() {
 			public void run() {
-				viewer.refresh();
+				if (viewer != null && !viewer.getControl().isDisposed())
+					viewer.refresh();
 			}
 		});
 	}
 
+	private IPreferenceStore getStore() {
+		return SimulationActivator.getDefault().getPreferenceStore();
+	}
+
+	private boolean hideTimeEvents() {
+		return getStore().getBoolean(HideTimeEventsAction.HIDE_KEY);
+	}
+
+	public void propertyChange(PropertyChangeEvent event) {
+		if (event.getProperty() == HideTimeEventsAction.HIDE_KEY) {
+			if (viewer != null && !viewer.getControl().isDisposed())
+				viewer.refresh();
+		}
+	}
+
+	/**
+	 * Container for grouping variables and events
+	 * 
+	 */
+	public static class Container {
+		String name = "Default";
+		List<AbstractSlot> slots = new ArrayList<AbstractSlot>();
+
+		public Container() {
+			super();
+		}
+
+		public Container(String name) {
+			this.name = name;
+		}
+
+		@Override
+		public int hashCode() {
+			final int prime = 31;
+			int result = 1;
+			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 (name == null) {
+				if (other.name != null)
+					return false;
+			} else if (!name.equals(other.name))
+				return false;
+			return true;
+		}
+
+	}
+
 }

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

@@ -65,7 +65,7 @@ public class ExecutionContextLabelProvider extends StyledCellLabelProvider {
 			style1.length = event.getName().length();
 			style1.underline = true;
 			style1.foreground = ColorConstants.lightBlue;
-			cell.setText(event.getName());
+			cell.setText(event.getSimpleName());
 			cell.setStyleRanges(new StyleRange[] { style1 });
 			if (event.getName().contains("time_event")) {
 				cell.setImage(DeclarationImages.TIMEEVENT.image());
@@ -74,7 +74,7 @@ public class ExecutionContextLabelProvider extends StyledCellLabelProvider {
 			}
 		} else if (element instanceof ExecutionVariable) {
 			ExecutionVariable variable = (ExecutionVariable) element;
-			cell.setText(variable.getName());
+			cell.setText(variable.getSimpleName());
 			cell.setImage(DeclarationImages.VARIABLE.image());
 		} else if (element instanceof Container) {
 			cell.setText(((Container) element).name);

+ 37 - 0
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/actions/CollapseAllAction.java

@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.ui.view.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.yakindu.sct.simulation.ui.DeclarationImages;
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class CollapseAllAction extends Action {
+
+	private TreeViewer fViewer;
+
+	public CollapseAllAction(TreeViewer viewer) {
+		super("Collapse all");
+		fViewer = viewer;
+		setToolTipText("Collapse all");
+		setImageDescriptor(DeclarationImages.COLLAPSE_ALL.imageDescriptor());
+	}
+
+	public void run() {
+		if (fViewer != null) {
+			fViewer.collapseAll();
+		}
+	}
+}

+ 38 - 0
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/actions/ExpandAllAction.java

@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.ui.view.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.yakindu.sct.simulation.ui.DeclarationImages;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class ExpandAllAction extends Action {
+
+	private TreeViewer fViewer;
+
+	public ExpandAllAction(TreeViewer viewer) {
+		super("Expand all");
+		fViewer = viewer;
+		setToolTipText("Expand all");
+		setImageDescriptor(DeclarationImages.EXPAND_ALL.imageDescriptor());
+	}
+
+	public void run() {
+		if (fViewer != null) {
+			fViewer.expandAll();
+		}
+	}
+}

+ 43 - 0
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/actions/HideTimeEventsAction.java

@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.ui.view.actions;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.yakindu.sct.simulation.ui.DeclarationImages;
+import org.yakindu.sct.simulation.ui.SimulationActivator;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class HideTimeEventsAction extends Action {
+
+	public static final String HIDE_KEY = "HideTimeEvents";
+
+	public HideTimeEventsAction(boolean show) {
+		super("Hide TimeEvents");
+		setToolTipText("Show TimeEvents");
+		setImageDescriptor(DeclarationImages.TIMEEVENT.imageDescriptor());
+		setChecked(getStore().getBoolean(HIDE_KEY));
+	}
+
+	@Override
+	public void run() {
+		boolean hide = getStore().getBoolean(HIDE_KEY);
+		getStore().setValue(HIDE_KEY, !hide);
+	}
+
+	private IPreferenceStore getStore() {
+		return SimulationActivator.getDefault().getPreferenceStore();
+	}
+}