Browse Source

Declaration View updated: Added LabelProvider with Icons, Event are displayed as hyperlinks

Andreas Mülder 14 years ago
parent
commit
c66daeef58

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


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


+ 66 - 0
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/DeclarationImages.java

@@ -0,0 +1,66 @@
+package org.yakindu.sct.simulation.ui;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public enum DeclarationImages {
+
+	EVENT("icons/Event.gif"),
+
+	VARIABLE("icons/Variable.gif");
+
+	private final String path;
+
+	private DeclarationImages(String path) {
+		this.path = path;
+	}
+
+	/**
+	 * Returns an image. Clients do not need to dispose the image, it will be
+	 * disposed automatically.
+	 * 
+	 * @return an {@link Image}
+	 */
+	public Image image() {
+		final ImageRegistry imageRegistry = SimulationActivator.getDefault()
+				.getImageRegistry();
+		Image image = imageRegistry.get(path);
+		if (image == null) {
+			addImageDescriptor();
+			image = imageRegistry.get(path);
+		}
+
+		return image;
+	}
+
+	/**
+	 * Returns an image descriptor.
+	 * 
+	 * @return an {@link ImageDescriptor}
+	 */
+	public ImageDescriptor imageDescriptor() {
+		final ImageRegistry imageRegistry = SimulationActivator.getDefault()
+				.getImageRegistry();
+		ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(path);
+		if (imageDescriptor == null) {
+			addImageDescriptor();
+			imageDescriptor = imageRegistry.getDescriptor(path);
+		}
+
+		return imageDescriptor;
+	}
+
+	private void addImageDescriptor() {
+		final SimulationActivator plugin = SimulationActivator.getDefault();
+		final ImageDescriptor id = ImageDescriptor.createFromURL(plugin
+				.getBundle().getEntry(path));
+		plugin.getImageRegistry().put(path, id);
+	}
+
+}

+ 19 - 266
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/DeclarationView.java

@@ -21,7 +21,9 @@ import org.eclipse.debug.ui.contexts.DebugContextEvent;
 import org.eclipse.debug.ui.contexts.IDebugContextListener;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
@@ -31,7 +33,7 @@ import org.eclipse.swt.widgets.Display;
 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.ui.model.presenter.IDynamicNotationHandler;
+import org.yakindu.sct.simulation.core.runtime.impl.ExecutionEvent;
 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;
@@ -61,7 +63,8 @@ public class DeclarationView extends AbstractDebugView implements
 
 	@Override
 	protected Viewer createViewer(Composite parent) {
-		viewer = new TreeViewer(parent);
+		viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL
+				| SWT.FULL_SELECTION);
 		viewer.getTree().setHeaderVisible(true);
 		viewer.getTree().setLinesVisible(true);
 		TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.DEFAULT);
@@ -78,15 +81,20 @@ public class DeclarationView extends AbstractDebugView implements
 				new BooleanEditingSupport(viewer), new IntegerEditingSupport(
 						viewer), new RealEditingSupport(viewer)));
 		valueColumn.setLabelProvider(new ExecutionContextLabelProvider(1));
-
-		TreeViewerColumn raiseEventColumn = new TreeViewerColumn(viewer,
-				SWT.DEFAULT);
-		raiseEventColumn.getColumn().setText("Raise");
-		raiseEventColumn.getColumn().setMoveable(true);
-		raiseEventColumn.getColumn().setWidth(50);
-		raiseEventColumn.setLabelProvider(new ExecutionContextLabelProvider(0));
-
 		viewer.setContentProvider(new ExecutionContextContentProvider());
+		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+			public void selectionChanged(SelectionChangedEvent event) {
+				Object firstElement = ((IStructuredSelection) event
+						.getSelection()).getFirstElement();
+				if (firstElement instanceof ExecutionEvent) {
+					IExecutionContext input = (IExecutionContext) viewer
+							.getInput();
+					input.raiseEvent(((ExecutionEvent) firstElement).getName(),
+							null);
+				}
+			}
+		});
+
 		return viewer;
 	}
 
@@ -96,7 +104,7 @@ public class DeclarationView extends AbstractDebugView implements
 					.getContext()).getFirstElement();
 			SCTDebugTarget debugTarget = (SCTDebugTarget) object
 					.getAdapter(IDebugTarget.class);
-			if (!debugTarget.isTerminated())
+			if (debugTarget != null && !debugTarget.isTerminated())
 				refreshInput(debugTarget);
 		}
 
@@ -147,259 +155,4 @@ public class DeclarationView extends AbstractDebugView implements
 
 	}
 
-	public IExecutionContext getExecutionContext() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	// private TableViewer eventViewer;
-	//
-	// private TableViewer variableViewer;
-	//
-	// private Map<Control, SelectionListener> controls;
-	// private Map<Control, TableEditor> tableEditors;
-	//
-	// //private SimulationSession activeSession;
-	//
-	// public DeclarationView() {
-	// controls = new HashMap<Control, SelectionListener>();
-	// tableEditors = new HashMap<Control, TableEditor>();
-	// }
-	//
-	// @Override
-	// public void init(IViewSite site) throws PartInitException {
-	// super.init(site);
-	// DebugUITools.getDebugContextManager()
-	// .getContextService(site.getWorkbenchWindow())
-	// .addDebugContextListener(this);
-	// }
-	//
-	// @Override
-	// public void createPartControl(Composite parent) {
-	// parent.setLayout(new GridLayout(1, true));
-	// createEventViewer(parent);
-	// createVariableViewer(parent);
-	// }
-	//
-	// private void createVariableViewer(Composite parent) {
-	// variableViewer = createTableViewer(parent);
-	// createScopeSlotColumns(variableViewer);
-	// setVariableViewerInput();
-	// }
-	//
-	// private void createEventViewer(Composite parent) {
-	// eventViewer = createTableViewer(parent);
-	// createScopeSlotColumns(eventViewer);
-	// createColumn(eventViewer, "raise", 50, 3);
-	// setEventViewerInput();
-	// }
-	//
-	// private TableViewer createTableViewer(Composite parent) {
-	// TableViewer viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
-	// | SWT.V_SCROLL | SWT.FULL_SELECTION);
-	// viewer.getTable().setLinesVisible(true);
-	// viewer.getTable().setHeaderVisible(true);
-	// GridDataFactory.fillDefaults().grab(true, true)
-	// .applyTo(viewer.getTable());
-	// viewer.setContentProvider(new ArrayContentProvider());
-	// return viewer;
-	// }
-	//
-	// private TableViewerColumn createColumn(TableViewer viewer, String text,
-	// int width, int index) {
-	// TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
-	// column.getColumn().setText(text);
-	// column.getColumn().setWidth(width);
-	// column.getColumn().setResizable(true);
-	// column.getColumn().setMoveable(true);
-	// column.setLabelProvider(new ScopeSlotLabelProvider(index));
-	// return column;
-	// }
-	//
-	// private void createScopeSlotColumns(TableViewer viewer) {
-	// // createColumn(viewer, "name", 80, 0);
-	// // createColumn(viewer, "type", 80, 1);
-	// // TableViewerColumn valueColumn = createColumn(viewer, "value", 80, 2);
-	// // valueColumn.setEditingSupport(new MultiEditingSupport(viewer,
-	// // new BooleanEditingSupport(viewer, this),
-	// // new IntegerEditingSupport(viewer, this),
-	// // new RealEditingSupport(viewer, this)));
-	// }
-	//
-	// @Override
-	// public void setFocus() {
-	// eventViewer.getTable().setFocus();
-	// }
-	//
-	// public void setEventViewerInput() {
-	// // if (activeSession != null) {
-	// // List<ExecutionEvent> events = activeSession.getExecutionContext()
-	// // .getDeclaredEvents();
-	// //
-	// // eventViewer.setInput(events);
-	// //
-	// // TableItem[] items = eventViewer.getTable().getItems();
-	// // for (TableItem tableItem : items) {
-	// // final TableEditor tableEditor = new TableEditor(
-	// // eventViewer.getTable());
-	// // tableEditor.horizontalAlignment = SWT.LEFT;
-	// // tableEditor.grabHorizontal = true;
-	// // tableEditor.grabVertical = true;
-	// // Button button = new Button(eventViewer.getTable(), SWT.FLAT);
-	// // button.setText("raise");
-	// // ButtonListener listener = new ButtonListener(
-	// // tableItem.getText());
-	// // button.addSelectionListener(listener);
-	// // tableEditor.setEditor(button, tableItem, 3);
-	// // tableEditors.put(button, tableEditor);
-	// // controls.put(button, listener);
-	// // }
-	// // }
-	// }
-	//
-	// private void setVariableViewerInput() {
-	// // if (activeSession != null) {
-	// // List<ExecutionVariable> variables = activeSession
-	// // .getExecutionContext().getVariables();
-	// // variableViewer.setInput(variables);
-	// // }
-	// }
-	//
-	// public void clearViewerInput(boolean disposeControls) {
-	// // clear the viewer input. This has to be done before the Buttons are
-	// // disposed. Otherwise listeners the TableViewer adds to Buttons can't
-	// // be removed from them what leads to a memory leak.
-	// eventViewer.setInput(null);
-	// eventViewer.refresh();
-	// variableViewer.setInput(null);
-	// eventViewer.refresh();
-	//
-	// for (Control control : controls.keySet()) {
-	// if (control instanceof Button) {
-	// // Listeners have to be removed manually otherwise the garbage
-	// // collector can't cleanup the button
-	// if (controls.get(control) != null) {
-	// ((Button) control).removeSelectionListener(controls
-	// .get(control));
-	// }
-	// // Same for the tableEditor
-	// if (tableEditors.get(control) != null) {
-	// tableEditors.get(control).dispose();
-	// }
-	// }
-	// if (disposeControls) {
-	// control.dispose();
-	// }
-	// }
-	// // if the controls are disposed they are never used again and should not
-	// // use memory anymore.
-	// controls.clear();
-	// tableEditors.clear();
-	// }
-	//
-	// // @Override
-	// // public void dispose() {
-	// // clearViewerInput(false);
-	// // super.dispose();
-	// // }
-	//
-	// private final class ButtonListener implements SelectionListener {
-	//
-	// private final String eventName;
-	//
-	// public ButtonListener(String eventName) {
-	// this.eventName = eventName;
-	// }
-	//
-	// public void widgetSelected(SelectionEvent e) {
-	// // if (activeSession != null) {
-	// // activeSession.raiseEvent(new ExecutionEvent(eventName));
-	// // }
-	// }
-	//
-	// public void widgetDefaultSelected(SelectionEvent e) {
-	// // Nothing to do
-	// }
-	//
-	// }
-	//
-	// public void debugContextChanged(DebugContextEvent event) {
-	// // StructuredSelection strSel = (StructuredSelection) event.getContext();
-	// // PlatformObject firstElement = (PlatformObject)
-	// strSel.getFirstElement();
-	// // if (firstElement == null) {
-	// // return;
-	// // }
-	// // SimulationSession selectedSession = (SimulationSession) firstElement
-	// // .getAdapter(SimulationSession.class);
-	// // if (selectedSession == null
-	// // || selectedSession.getCurrentState() == SimulationState.TERMINATED) {
-	// // activeSession = selectedSession;
-	// // clearViewerInput(true);
-	// // }
-	// // if (!(selectedSession == activeSession) && selectedSession != null) {
-	// // if (activeSession != null) {
-	// // activeSession.removeSimulationListener(this);
-	// // activeSession.getExecutionContext()
-	// // .removeExecutionContextListener(this);
-	// // }
-	// // activeSession = selectedSession;
-	// // selectedSession.addSimulationListener(this);
-	// // selectedSession.getExecutionContext().addExecutionContextListener(
-	// // this);
-	// // clearViewerInput(true);
-	// // setEventViewerInput();
-	// // setVariableViewerInput();
-	// // }
-	// }
-	// //
-	// // public SimulationSession getActiveSession() {
-	// // return activeSession;
-	// // }
-	// //
-	// // public void simulationStateChanged(SimulationState oldState,
-	// // SimulationState newState) {
-	// // switch (newState) {
-	// // case STARTED:
-	// // Display.getDefault().asyncExec(new Runnable() {
-	// // public void run() {
-	// // setEventViewerInput();
-	// // setVariableViewerInput();
-	// // }
-	// // });
-	// // break;
-	// // case TERMINATED:
-	// // Display.getDefault().asyncExec(new Runnable() {
-	// // public void run() {
-	// // clearViewerInput(true);
-	// // }
-	// // });
-	// // ;
-	// // break;
-	// // }
-	// // }
-	//
-	// public void variableDeclared(ExecutionVariable variable) {
-	// // Nothing to do
-	// }
-	//
-	// public void eventDeclared(ExecutionEvent event) {
-	// // Nothing to do
-	// }
-	//
-	// public void eventRaised(ExecutionEvent event) {
-	// Display.getDefault().asyncExec(new Runnable() {
-	// public void run() {
-	// setEventViewerInput();
-	// }
-	// });
-	// }
-	//
-	// public void variableValueChanged(ExecutionVariable variable) {
-	// Display.getDefault().asyncExec(new Runnable() {
-	// public void run() {
-	// setVariableViewerInput();
-	// }
-	// });
-	// }
 }

+ 15 - 6
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ExecutionContextContentProvider.java

@@ -1,3 +1,13 @@
+/**
+ * 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;
 
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -11,6 +21,11 @@ import org.yakindu.sct.simulation.core.runtime.impl.ExecutionVariable;
 
 import com.google.common.collect.Iterables;
 
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
 public class ExecutionContextContentProvider implements ITreeContentProvider,
 		IExecutionContextListener {
 
@@ -54,12 +69,6 @@ public class ExecutionContextContentProvider implements ITreeContentProvider,
 		return false;
 	}
 
-	public void variableDeclared(ExecutionVariable variable) {
-	}
-
-	public void eventDeclared(ExecutionEvent event) {
-	}
-
 	public void eventRaised(ExecutionEvent event) {
 	}
 

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

@@ -1,44 +1,76 @@
+/**
+ * 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;
 
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.custom.StyleRange;
 import org.yakindu.sct.simulation.core.runtime.impl.AbstractSlot;
 import org.yakindu.sct.simulation.core.runtime.impl.ExecutionEvent;
-
-public class ExecutionContextLabelProvider extends ColumnLabelProvider {
+import org.yakindu.sct.simulation.core.runtime.impl.ExecutionVariable;
+import org.yakindu.sct.simulation.ui.DeclarationImages;
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public class ExecutionContextLabelProvider extends StyledCellLabelProvider {
 
 	private final int index;
-
+	
 	public ExecutionContextLabelProvider(int index) {
 		this.index = index;
 	}
 
-	@Override
-	public String getText(Object element) {
-		AbstractSlot abstractSlot = (AbstractSlot) element;
+	public void update(ViewerCell cell) {
 		switch (index) {
 		case 0:
-			return abstractSlot.getName();
+			updateNameCell(cell);
+			break;
 		case 1:
-			if (abstractSlot.getValue() != null)
-				return abstractSlot.getValue().toString();
-		default:
-			return "";
+			updateValueCell(cell);
+			break;
 		}
+		super.update(cell);
 	}
 
-	@Override
-	public Image getImage(Object element) {
-		return super.getImage(element);
+	private void updateValueCell(ViewerCell cell) {
+		Object element = cell.getElement();
+		if (element instanceof AbstractSlot) {
+			Object value = ((AbstractSlot) element).getValue();
+			if (value != null)
+				cell.setText(value.toString());
+		}
+
 	}
-	
-	@Override
-	public Font getFont(Object element) {
-		if(element instanceof ExecutionEvent){
-			
+
+	private void updateNameCell(ViewerCell cell) {
+		Object element = cell.getElement();
+		if (element instanceof ExecutionEvent) {
+			ExecutionEvent event = (ExecutionEvent) element;
+			cell.setText(event.getName());
+			StyleRange style1 = new StyleRange();
+			style1.start = 0;
+			style1.length = event.getName().length();
+			style1.underline = true;
+			style1.foreground = ColorConstants.lightBlue;
+			cell.setText(event.getName());
+			cell.setStyleRanges(new StyleRange[] { style1 });
+			cell.setImage(DeclarationImages.EVENT.image());
+		} else if (element instanceof ExecutionVariable) {
+			ExecutionVariable variable = (ExecutionVariable) element;
+			cell.setText(variable.getName());
+			cell.setImage(DeclarationImages.VARIABLE.image());
 		}
-		return super.getFont(element);
 	}
 
 }

+ 0 - 47
plugins/org.yakindu.sct.simulation.ui/src/org/yakindu/sct/simulation/ui/view/ScopeSlotLabelProvider.java

@@ -1,47 +0,0 @@
-/**
- * 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;
-
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.yakindu.sct.simulation.core.runtime.impl.AbstractSlot;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public class ScopeSlotLabelProvider extends ColumnLabelProvider {
-
-	private final int index;
-
-	public ScopeSlotLabelProvider(int index) {
-		this.index = index;
-	}
-
-	@Override
-	public String getText(Object element) {
-		switch (index) {
-		case 0:
-			// NAME
-			return ((AbstractSlot) element).getName();
-		case 1:
-			// TYPE
-			Class<?> type = ((AbstractSlot) element).getType();
-			return type != null ? type.getSimpleName() : null;
-		case 2:
-			// VALUE:
-			Object value = ((AbstractSlot) element).getValue();
-			return value != null ? value.toString() : null;
-		default:
-			return "";
-		}
-	}
-}