Sfoglia il codice sorgente

Added Simulation Launch Tab

Andreas Mülder 14 anni fa
parent
commit
03a289c7b3

+ 31 - 0
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/launch/IStatechartLaunchParameters.java

@@ -0,0 +1,31 @@
+/**
+ * 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.core.simulation.launch;
+
+/**
+ * Attribute constants for the YAKINDU Statechart launch configuration.
+ * 
+ * @author andreas muelder
+ * 
+ */
+public interface IStatechartLaunchParameters {
+
+	// Attribute keys
+	String FILE_NAME = "filename";
+	String YACOP_ENABLED = "yacopEnabled";
+	String YACOP_PORT = "yacopPort";
+
+	// Attribute default values
+	String DEFAULT_FILE_NAME = "";
+	boolean DEFAULT_YACOP_ENABLED = false;
+	String DEFAULT_YACOP_PORT = "1234";
+
+}

+ 3 - 2
plugins/org.yakindu.sct.core.simulation/src/org/yakindu/sct/core/simulation/launch/StatechartLaunchConfigurationDelegate.java

@@ -27,9 +27,10 @@ public class StatechartLaunchConfigurationDelegate implements
 	@Override
 	public void launch(ILaunchConfiguration configuration, String mode,
 			ILaunch launch, IProgressMonitor monitor) throws CoreException {
+		String filename = configuration.getAttribute(
+				IStatechartLaunchParameters.FILE_NAME, "");
 
-		System.out.println("Launching simulation.....");
-		
+		System.out.println("Launching simulation for file " + filename);
 	}
 
 }

+ 4 - 1
plugins/org.yakindu.sct.ui.simulation/META-INF/MANIFEST.MF

@@ -12,6 +12,9 @@ Require-Bundle: org.eclipse.ui,
  org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.4.1",
  org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
  org.eclipse.debug.ui;bundle-version="3.7.0",
- org.yakindu.sct.core.simulation;bundle-version="1.0.0"
+ org.yakindu.sct.core.simulation;bundle-version="1.0.0",
+ org.eclipse.jdt.launching;bundle-version="3.6.0",
+ org.eclipse.jdt.debug.ui;bundle-version="3.6.0"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
+Import-Package: org.eclipse.ui.dialogs

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

@@ -25,6 +25,7 @@ import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.IEditorPart;
 import org.yakindu.sct.core.simulation.launch.IStatechartLaunchConfigurationType;
+import org.yakindu.sct.core.simulation.launch.IStatechartLaunchParameters;
 
 /**
  * 
@@ -32,7 +33,7 @@ import org.yakindu.sct.core.simulation.launch.IStatechartLaunchConfigurationType
  * 
  */
 public class StatechartLaunchShortcut implements ILaunchShortcut,
-		IStatechartLaunchConfigurationType {
+		IStatechartLaunchConfigurationType, IStatechartLaunchParameters {
 
 	public void launch(ISelection selection, String mode) {
 		if (selection instanceof IStructuredSelection) {
@@ -67,7 +68,10 @@ public class StatechartLaunchShortcut implements ILaunchShortcut,
 			ILaunchConfigurationWorkingCopy newConfig = configType.newInstance(
 					null, launchManager.generateLaunchConfigurationName(file
 							.getName()));
+
+			newConfig.setAttribute(FILE_NAME, file.getFullPath().toFile().getAbsolutePath());
 			return newConfig.doSave();
+			
 		} catch (CoreException e) {
 			e.printStackTrace();
 		}

+ 204 - 0
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/launch/tabs/StatechartLaunchConfigurationTab.java

@@ -0,0 +1,204 @@
+/**
+ * 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.ui.simulation.launch.tabs;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchTab;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ResourceListSelectionDialog;
+import org.yakindu.sct.core.simulation.launch.IStatechartLaunchParameters;
+
+/**
+ * 
+ * @author andreas muelder
+ * 
+ */
+public class StatechartLaunchConfigurationTab extends JavaLaunchTab implements
+		IStatechartLaunchParameters {
+
+	private Image image;
+	private Text modelfile;
+	private Button btnYacopEnabled;
+	private Text port;
+
+	public StatechartLaunchConfigurationTab() {
+		image = new Image(Display.getDefault(), getClass().getClassLoader()
+				.getResourceAsStream("icons/yakindu.png"));
+	}
+
+	public void createControl(Composite parent) {
+		Composite comp = new Composite(parent, SWT.NONE);
+		setControl(comp);
+		comp.setLayout(new GridLayout(1, true));
+		createFileSelectionGroup(comp);
+		new Label(comp, SWT.NONE);
+		createYacopGroup(comp);
+	}
+
+	private void createYacopGroup(Composite comp) {
+		Group yacopGroup = new Group(comp, SWT.NONE);
+		yacopGroup.setText("YAKINDU Communication Protocol:");
+		GridDataFactory.fillDefaults().grab(true, false).applyTo(yacopGroup);
+		GridLayout layout = new GridLayout(2, false);
+		layout.horizontalSpacing = 15;
+		yacopGroup.setLayout(layout);
+
+		btnYacopEnabled = new Button(yacopGroup, SWT.CHECK);
+		GridDataFactory.fillDefaults().grab(true, false).span(2, 0)
+				.applyTo(btnYacopEnabled);
+		btnYacopEnabled.setText("enable protocol");
+		btnYacopEnabled.addSelectionListener(new SelectionListener() {
+
+			public void widgetSelected(SelectionEvent e) {
+				port.setEnabled(!port.getEnabled());
+				updateLaunchConfigurationDialog();
+			}
+
+			public void widgetDefaultSelected(SelectionEvent e) {
+				// Nothing to do
+			}
+		});
+
+		Label label = new Label(yacopGroup, SWT.NONE);
+		label.setText("socket server port: ");
+		GridDataFactory.fillDefaults().grab(false, false).applyTo(label);
+
+		port = new Text(yacopGroup, SWT.BORDER);
+		port.addModifyListener(new UpdateListener());
+		GridDataFactory.fillDefaults().grab(true, false).applyTo(port);
+
+	}
+
+	private void createFileSelectionGroup(Composite comp) {
+		Group fileGroup = new Group(comp, SWT.NONE);
+		GridDataFactory.fillDefaults().grab(true, false).applyTo(fileGroup);
+		fileGroup.setText("Model file:");
+		fileGroup.setLayout(new GridLayout(2, false));
+
+		modelfile = new Text(fileGroup, SWT.BORDER);
+		modelfile.addModifyListener(new UpdateListener());
+		GridDataFactory.fillDefaults().grab(true, false).applyTo(modelfile);
+
+		Button browse = new Button(fileGroup, SWT.NONE);
+		browse.setText("Search");
+		browse.addSelectionListener(new SelectionListener() {
+
+			public void widgetSelected(SelectionEvent e) {
+				ResourceListSelectionDialog dialog = new ResourceListSelectionDialog(
+						getShell(), ResourcesPlugin.getWorkspace().getRoot(),
+						IResource.FILE);
+				dialog.setTitle("Select Statechart model");
+				dialog.setMessage("Please select the YAKINDU statechart model file you want to execute.");
+				if (dialog.open() == 0) {
+					Object[] files = dialog.getResult();
+					IFile file = (IFile) files[0];
+					modelfile.setText((file.getFullPath().toString()));
+				}
+			}
+
+			public void widgetDefaultSelected(SelectionEvent e) {
+				// Nothing to do
+			}
+		});
+
+		GridDataFactory.fillDefaults().applyTo(browse);
+
+	}
+
+	public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+		configuration.setAttribute(YACOP_ENABLED, DEFAULT_YACOP_ENABLED);
+		configuration.setAttribute(YACOP_PORT, DEFAULT_YACOP_PORT);
+	}
+
+	public void initializeFrom(ILaunchConfiguration configuration) {
+		try {
+			modelfile.setText(configuration.getAttribute(FILE_NAME,
+					DEFAULT_FILE_NAME));
+			btnYacopEnabled.setSelection(configuration.getAttribute(
+					YACOP_ENABLED, DEFAULT_YACOP_ENABLED));
+			if (btnYacopEnabled.getSelection()) {
+				port.setEnabled(true);
+			} else {
+				port.setEnabled(false);
+			}
+			port.setText(configuration.getAttribute(YACOP_PORT,
+					DEFAULT_YACOP_PORT));
+
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+		configuration.setAttribute(FILE_NAME, modelfile.getText());
+		configuration.setAttribute(YACOP_PORT, port.getText());
+		configuration.setAttribute(YACOP_ENABLED,
+				btnYacopEnabled.getSelection());
+	}
+
+	@Override
+	public void dispose() {
+		image.dispose();
+		super.dispose();
+	}
+
+	public String getName() {
+		return "Main";
+	}
+
+	@Override
+	public Image getImage() {
+		return image;
+	}
+
+	@Override
+	public boolean isValid(ILaunchConfiguration launchConfig) {
+		setMessage(null);
+		setErrorMessage(null);
+		String model = this.modelfile.getText().trim();
+		if (model.length() > 0)
+			if (ResourcesPlugin.getWorkspace().getRoot().findMember(model) == null) {
+				setErrorMessage("file " + model + " does not exist!");
+				return false;
+			}
+		// TODO: Add validation for port
+
+		return super.isValid(launchConfig);
+	}
+
+	private class UpdateListener implements ModifyListener {
+
+		public void modifyText(ModifyEvent e) {
+			StatechartLaunchConfigurationTab.this
+					.updateLaunchConfigurationDialog();
+		}
+
+	}
+
+}

+ 1 - 3
plugins/org.yakindu.sct.ui.simulation/src/org/yakindu/sct/ui/simulation/launch/tabs/StatechartLaunchConfigurationTabGroup.java

@@ -26,9 +26,7 @@ public class StatechartLaunchConfigurationTabGroup extends
 	}
 
 	public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
-		ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
-		// TODO: Tabs here....
-		};
+		ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { new StatechartLaunchConfigurationTab() };
 		setTabs(tabs);
 	}