From: <jhs...@us...> - 2009-04-12 15:47:03
|
Revision: 150 http://flexotask.svn.sourceforge.net/flexotask/?rev=150&view=rev Author: jhspring Date: 2009-04-12 15:46:57 +0000 (Sun, 12 Apr 2009) Log Message: ----------- Initial import. Added Paths: ----------- trunk/flexotask-streaming/.classpath trunk/flexotask-streaming/.project trunk/flexotask-streaming/META-INF/ trunk/flexotask-streaming/META-INF/MANIFEST.MF trunk/flexotask-streaming/build.properties trunk/flexotask-streaming/debug.xml trunk/flexotask-streaming/getstreamit-licensing.txt trunk/flexotask-streaming/getstreamit.xml trunk/flexotask-streaming/plugin.xml trunk/flexotask-streaming/src/ trunk/flexotask-streaming/src/META-INF/ trunk/flexotask-streaming/src/META-INF/services/ trunk/flexotask-streaming/src/META-INF/services/com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulerFactory trunk/flexotask-streaming/src/com/ trunk/flexotask-streaming/src/com/ibm/ trunk/flexotask-streaming/src/com/ibm/realtime/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORateCellEditor.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORatePropertyDescriptor.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/FlexotaskStreamingPlugin.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGlobalTiming.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGrammarProvider.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedLocalTiming.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorPropertyDescriptor.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorSelectingCellEditor.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/BlockingConnectionRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/ConnectionRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/CrossChainConnectionRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/DefaultWorkVisitor.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/NotifyingConnectionRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/Runner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/RunnerMaker.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/SchedulerMasterRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/SchedulerSlaveRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/StreamBackEndFactory.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/StreamComputeNode.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/StreamComputeNodes.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/StreamScheduler.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/StreamSchedulerFactory.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/StreamSchedulerMasterRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/StreamSchedulerSlaveRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/TaskRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/scheduling/streaming/TimedTaskRunner.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/timing/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/timing/streaming/ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/timing/streaming/FlexotaskTaskIORate.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/timing/streaming/FlexotaskTaskPortMuxMode.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/timing/streaming/StreamBasedGlobalTimingData.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/timing/streaming/StreamBasedTimingAnnotation.java trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/timing/streaming/StreamBasedTimingDataParser.java Added: trunk/flexotask-streaming/.classpath =================================================================== --- trunk/flexotask-streaming/.classpath (rev 0) +++ trunk/flexotask-streaming/.classpath 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry exported="true" kind="lib" path="streamit.jar" sourcepath="streamitsrc.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/flexotask-streaming/.project =================================================================== --- trunk/flexotask-streaming/.project (rev 0) +++ trunk/flexotask-streaming/.project 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>flexotask-streaming</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + <dictionary> + <key>LaunchConfigHandle</key> + <value><project>/.externalToolBuilders/flexotask-streaming debug.xml [Builder].launch</value> + </dictionary> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Added: trunk/flexotask-streaming/META-INF/MANIFEST.MF =================================================================== --- trunk/flexotask-streaming/META-INF/MANIFEST.MF (rev 0) +++ trunk/flexotask-streaming/META-INF/MANIFEST.MF 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Flexotask Streaming Scheduler and Timing Grammar Plug-in +Bundle-SymbolicName: com.ibm.realtime.flexotask.streaming;singleton:=true +Bundle-Version: 1.1.0 +Bundle-Activator: com.ibm.realtime.flexotask.editor.timing.streaming.FlexotaskStreamingPlugin +Bundle-Vendor: IBM Research and EPFL +Require-Bundle: com.ibm.realtime.analysis, + com.ibm.realtime.flexotask, + com.ibm.realtime.flexotask.editor, + org.eclipse.ui, + org.eclipse.ui.views, + org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.draw2d, + org.eclipse.jdt.core, + org.eclipse.jdt.ui +Eclipse-LazyStart: true +Export-Package: com.ibm.realtime.flexotask.editor.dialogs.streaming, + com.ibm.realtime.flexotask.editor.timing.streaming, + com.ibm.realtime.flexotask.scheduling.streaming, + com.ibm.realtime.flexotask.timing.streaming +Bundle-ClassPath: flexotaskStreaming.jar, + streamit.jar Added: trunk/flexotask-streaming/build.properties =================================================================== --- trunk/flexotask-streaming/build.properties (rev 0) +++ trunk/flexotask-streaming/build.properties 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,7 @@ +output.. = bin/ +bin.includes = META-INF/,\ + flexotaskStreaming.jar,\ + plugin.xml,\ + streamit.jar,\ + flexotaskStreamingsrc.zip +source.flexotaskStreaming.jar = src/ Added: trunk/flexotask-streaming/debug.xml =================================================================== --- trunk/flexotask-streaming/debug.xml (rev 0) +++ trunk/flexotask-streaming/debug.xml 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project default="makezip"> + <target name="makezip"> + <delete file="debug.zip"/> + <zip destfile="debug.zip"> + <fileset dir="src"/> + <fileset dir="bin"/> + <zipfileset src="streamit.jar"/> + </zip> + </target> +</project> \ No newline at end of file Added: trunk/flexotask-streaming/getstreamit-licensing.txt =================================================================== --- trunk/flexotask-streaming/getstreamit-licensing.txt (rev 0) +++ trunk/flexotask-streaming/getstreamit-licensing.txt 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,5 @@ + +Be aware that the StreamIt binaries are distributed with their own licensing +requirements that are different from those applied to this Flexotask Stream +Scheduler project. Please read the licensing requirements of StreamIt before +downloading the binaries through the getstreamit Ant script. \ No newline at end of file Added: trunk/flexotask-streaming/getstreamit.xml =================================================================== --- trunk/flexotask-streaming/getstreamit.xml (rev 0) +++ trunk/flexotask-streaming/getstreamit.xml 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project default="getstreamit"> + + <property name="streamitfile" value="streamit-2.1.1.tar.gz"/> + <property name="tmp" value="tmp"/> + <property name="tmp.tar.gz" value="tmp.tar.gz"/> + <property name="tmp.tar" value="tmp.tar"/> + <property name="target.jar" value="streamit.jar"/> + + + <target name="getstreamit"> + <delete file="${target.jar}"/> + + <delete includeEmptyDirs="true" quiet="true"> + <fileset dir="${tmp}"/> + </delete> + + <mkdir dir="${tmp}"/> + + <get src="http://cag.lcs.mit.edu/streamit/restricted/${streamitfile}" dest="${tmp}/${tmp.tar.gz}" /> + + <gunzip src="${tmp}/${tmp.tar.gz}" dest="${tmp}/${tmp.tar}"/> + + <untar src="${tmp}/${tmp.tar}" dest="${tmp}/../"> + <patternset> + <include name="**/streamit.jar"/> + </patternset> + <mapper type="flatten"/> + </untar> + + <delete includeEmptyDirs="true" quiet="true"> + <fileset dir="${tmp}"/> + </delete> + </target> +</project> \ No newline at end of file Added: trunk/flexotask-streaming/plugin.xml =================================================================== --- trunk/flexotask-streaming/plugin.xml (rev 0) +++ trunk/flexotask-streaming/plugin.xml 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> +<plugin> + <extension + id="com.ibm.realtime.flexotask.editor.timing.streaming.StreamBasedGrammarProvider" + name="Stream-based Timing Grammar Provider" + point="com.ibm.realtime.flexotask.editor.TimingGrammar"> + <handler + class="com.ibm.realtime.flexotask.editor.timing.streaming.StreamBasedGrammarProvider" + kind="Stream-based Timing Grammar Provider"> + </handler> + </extension> +</plugin> Added: trunk/flexotask-streaming/src/META-INF/services/com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulerFactory =================================================================== --- trunk/flexotask-streaming/src/META-INF/services/com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulerFactory (rev 0) +++ trunk/flexotask-streaming/src/META-INF/services/com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulerFactory 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,2 @@ +# Declare the Streaming scheduler +com.ibm.realtime.flexotask.scheduling.streaming.StreamSchedulerFactory Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORateCellEditor.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORateCellEditor.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORateCellEditor.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,144 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.dialogs.streaming; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.swt.widgets.Composite; + +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.timing.streaming.FlexotaskTaskIORate; + +/** + * An extended text cell editor capable of validating if the entered value + * represents a valid task I/O rate. + */ +public class TaskIORateCellEditor extends TextCellEditor { + + /** Last value set by doSetValue */ + Object lastValue = ""; + + /** Flag indicating that the error message dialog is running. This suppresses the usual + * behavior of focusLost and keyReleaseOccurred so that the dialog doesn't get fired too + * many times. + */ + private boolean dialogRunning; + + /** + * Constructor. + * @param parent + */ + public TaskIORateCellEditor(Composite parent) { + super(parent); + } + + // @see org.eclipse.jface.viewers.TextCellEditor#doGetValue() + protected Object doGetValue() { + String value = (String) super.doGetValue(); + + try { + lastValue = FlexotaskTaskIORate.getTaskIORate(value).toString(); + return lastValue; + } + catch (FlexotaskValidationException e) { + setValueValid(false); + displayFormatErrorMessage(); + } + return lastValue.toString(); + } + + // @see org.eclipse.jface.viewers.TextCellEditor#doSetValue(java.lang.Object) + protected void doSetValue(Object value) + { + if (value == null) { + lastValue = ""; + return; + } + try { + lastValue = FlexotaskTaskIORate.getTaskIORate((String) value).toString(); + setValueValid(true); + super.doSetValue(lastValue); + } + catch (FlexotaskValidationException e) { + setValueValid(false); + displayFormatErrorMessage(); + } + } + + private void displayFormatErrorMessage() { + if (!dialogRunning) { + /* Display error message */ + String[] buttonLabels = new String[] {"Ok"}; + String message = "The format of the specified port rate is incorrect. Please correct!\n\n" + + "Valid formats are:\n1) N (the definite rate)\n" + + "2) [N, N] (a rate range from minimum to maximum)\n" + + "3) [N, N, N] (a rate range from minimum over average to maximum)\n" + + "\nwhere N is a positive integer."; + + MessageDialog dialog = new MessageDialog(getControl().getShell(), "Incorrect format!", + null, message, MessageDialog.ERROR, buttonLabels, 2); + dialogRunning = true; + dialog.open(); + dialogRunning = false; + } + } + /* + private boolean isRateValueValid(String value) { + try { + Integer i = new Integer(value); + if (i > 0) return true; + } + catch (Exception e) { + return false; + } + return false; + } + + private TaskIORate parseValue(Object value) { + if (value == null) return new TaskIORate(); + String str = ((String) value).trim(); + // no rate specified + if (str.length() == 0) return new TaskIORate(); + // check specified rate + if (str.startsWith("[")) { // range specified + if (!str.endsWith("]")) { + throw new IllegalArgumentException(); + } + str = str.substring(1, str.length() - 1); + StringTokenizer st = new StringTokenizer(str, ","); + if (st.countTokens() < 2 || st.countTokens() > 3) + throw new IllegalArgumentException(); + int[] values = new int[3]; + int count = 0; + while (st.hasMoreTokens()) { + String token = st.nextToken().trim(); + if (isRateValueValid(token)) + values[count++] = new Integer(token).intValue(); + else throw new IllegalArgumentException(); + } + if (count == 2) + return new TaskIORate(values[0], values[1]); + else + return new TaskIORate(values[0], values[1], values[2]); + } + else { // single value specified + if (isRateValueValid(str)) { + return new TaskIORate(new Integer(str).intValue()); + } + } + throw new IllegalArgumentException(); + }*/ +} Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORatePropertyDescriptor.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORatePropertyDescriptor.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/dialogs/streaming/TaskIORatePropertyDescriptor.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,42 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.dialogs.streaming; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.views.properties.PropertyDescriptor; + +/** + * A variation on TextPropertyDescriptor that uses a variation on TextCellEditor to post-process + * and disambiguate results when the entity being displayed is a port name. + */ +public class TaskIORatePropertyDescriptor extends PropertyDescriptor { + /** + * Create a new PortRatePropertyDescriptor + * @param id the property id + * @param displayName the display name + */ + public TaskIORatePropertyDescriptor(Object id, String displayName) + { + super(id, displayName); + } + + // @see org.eclipse.ui.views.properties.PropertyDescriptor#createPropertyEditor(org.eclipse.swt.widgets.Composite) + public CellEditor createPropertyEditor(Composite parent) + { + return new TaskIORateCellEditor(parent); + } +} Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/FlexotaskStreamingPlugin.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/FlexotaskStreamingPlugin.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/FlexotaskStreamingPlugin.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,56 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.timing.streaming; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +public class FlexotaskStreamingPlugin extends AbstractUIPlugin +{ + // The plug-in ID + public static final String PLUGIN_ID = "com.ibm.realtime.flexotask.streaming"; + + // The shared instance + private static FlexotaskStreamingPlugin plugin; + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static FlexotaskStreamingPlugin getDefault() { + return plugin; + } + +} Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGlobalTiming.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGlobalTiming.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGlobalTiming.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,387 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.timing.streaming; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.draw2d.Label; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.search.IJavaSearchConstants; +import org.eclipse.jdt.core.search.IJavaSearchScope; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.core.search.SearchMatch; +import org.eclipse.jdt.core.search.SearchParticipant; +import org.eclipse.jdt.core.search.SearchPattern; +import org.eclipse.jdt.core.search.SearchRequestor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.TextPropertyDescriptor; + +import com.ibm.realtime.flexotask.editor.dialogs.ClassSelectingCellEditor.ClassWrapper; +import com.ibm.realtime.flexotask.editor.model.Connection; +import com.ibm.realtime.flexotask.editor.model.GlobalTiming; +import com.ibm.realtime.flexotask.editor.model.LocalTiming; +import com.ibm.realtime.flexotask.editor.model.ModelElement; +import com.ibm.realtime.flexotask.editor.model.NormalTask; +import com.ibm.realtime.flexotask.editor.model.PortDeclaration; +import com.ibm.realtime.flexotask.editor.model.Task; +import com.ibm.realtime.flexotask.editor.model.TaskDiagram; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser; +import com.ibm.realtime.flexotask.timing.streaming.StreamBasedGlobalTimingData; + +/** + * The GlobalTiming annotator for the stream-based grammar + */ +public class StreamBasedGlobalTiming extends GlobalTiming implements PropertyChangeListener { + + /** Property ID for the period */ + private static final String PERIOD = "StreamBasedGlobalTimingPeriod"; + /** Property ID for the period */ + private static final String WORK_ESTIMATOR = "StreamBasedGlobalTimingWorkEstimator"; + + /** The property descriptors */ + private final IPropertyDescriptor[] descriptors = new IPropertyDescriptor[] { + new TextPropertyDescriptor(PERIOD, "Period"), + new WorkEstimatorPropertyDescriptor(WORK_ESTIMATOR, "Work Estimator Class (Optional)", this) + }; + + private StreamBasedGlobalTimingData timingData; + /** The Work Estimator used for estimating the amount each task performs. */ + private IType workEstimatorType; + + /** + * Create a new StreamBasedGlobalTiming + */ + public StreamBasedGlobalTiming() { + this(new StreamBasedGlobalTimingData(-1, null)); + } + + /** + * Create a new StreamBasedGlobalTiming + * @param period the Period annotation from which to initialize + * @param workEstimatorType the Work Estimator used for estimating the amount each + * task performs. + */ + public StreamBasedGlobalTiming(StreamBasedGlobalTimingData timingData) + { + this.timingData = timingData; + this.workEstimatorType = null; + if ((timingData.getWorkEstimator() != null) && (timingData.getWorkEstimator().length() > 0)) + this.workEstimatorType = resolveType(timingData.getWorkEstimator()); + computeToolTipAndColor(); + } + + // @see com.ibm.realtime.flexotask.editor.model.GlobalTiming#getAnnotation() + public FlexotaskTimingData getAnnotation() + { + return timingData; + } + + // @see com.ibm.realtime.flexotask.editor.model.GlobalTiming#getElementAnnotator(com.ibm.realtime.flexotask.editor.model.ModelElement) + public LocalTiming getElementAnnotator(ModelElement element) + { + return new StreamBasedLocalTiming(element); + } + + // @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() + public IPropertyDescriptor[] getPropertyDescriptors() + { + return descriptors; + } + + // @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) + public Object getPropertyValue(Object id) + { + if (PERIOD.equals(id)) + return (timingData.getPeriod() <= 0) ? "" : FlexotaskTimingDataParser.formatTime(timingData.getPeriod()); + else if (WORK_ESTIMATOR.equals(id)) + return new ClassWrapper(workEstimatorType); + return null; + } + + // @see com.ibm.realtime.flexotask.editor.model.ModelElement#getToolTipLabels(java.util.List) + public void getToolTipLabels(List<Label> labels) + { + Label label = new Label(); + if (timingData.getPeriod() <= 0) { + label.setIcon(WARNING_IMAGE); + label.setText("Period has not been specified"); + } else { + label.setIcon(OK_IMAGE); + label.setText("Period =" + FlexotaskTimingDataParser.formatTime(timingData.getPeriod())); + } + labels.add(label); + + label = new Label(); + labels.addAll(validateWorkEstimator()); + if (workEstimatorType != null) { + label.setIcon(OK_IMAGE); + label.setText("Work estimator class =" + workEstimatorType); + } else { + label.setIcon(OK_IMAGE); + label.setText("Work estimator class not set; using default!"); + } + labels.add(label); + } + + // @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) + public boolean isPropertySet(Object id) + { + if (PERIOD.equals(id)) + return timingData.getPeriod() > 0; + else if (WORK_ESTIMATOR.equals(id)) + return (workEstimatorType != null); + else + return false; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.ModelElement#getName() + */ + public String getName() + { + return "Stream-based Timing Mode"; + } + + // @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) + public void resetPropertyValue(Object id) + { + if (PERIOD.equals(id)) + setAnnotation(new StreamBasedGlobalTimingData(-1)); + else if (WORK_ESTIMATOR.equals(id)) + workEstimatorType = null; + } + + // @see com.ibm.realtime.flexotask.editor.model.GlobalTiming#setAnnotation(com.ibm.realtime.flexotask.timing.FlexotaskTimingData) + public void setAnnotation(FlexotaskTimingData annotation) + { + timingData = (StreamBasedGlobalTimingData) annotation; + computeToolTipAndColor(); + } + + // @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) + public void setPropertyValue(Object id, Object value) + { + if (PERIOD.equals(id)) { + if ((value == null) || (value.equals(""))) + timingData.setPeriod(-1); + else + timingData.setPeriod(FlexotaskTimingDataParser.parseTime((String) value)); + computeToolTipAndColor(); + } + else if (WORK_ESTIMATOR.equals(id)) { + this.workEstimatorType = ((ClassWrapper) value).classType; + if (workEstimatorType != null) + timingData.setWorkEstimator(workEstimatorType.getFullyQualifiedName()); + else + timingData.setWorkEstimator(null); + computeToolTipAndColor(); + } + } + + private IType resolveType(String implementation) + { + final IType[] ans = new IType[1]; + IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); + SearchPattern pattern = SearchPattern.createPattern(implementation, IJavaSearchConstants.CLASS, + IJavaSearchConstants.DECLARATIONS, + SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); + SearchEngine engine = new SearchEngine(); + SearchRequestor req = new SearchRequestor() { + public void acceptSearchMatch(SearchMatch match) throws CoreException + { + if (ans[0] == null) { + Object whatnot = match.getElement(); + if (whatnot instanceof IType) { + ans[0] = (IType) match.getElement(); + } + } + } + }; + try { + engine.search(pattern, new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, + scope, req, null); + } catch (CoreException e) { + return null; + } + return ans[0]; + } + + /** + * Validate the work estimator as having the right characteristics, i.e., that + * it implements the expected interface. In any case, problems are + * recorded for later display in the tooltip. + */ + private List<Label> validateWorkEstimator() { + List<Label> labels = new ArrayList<Label>(); + if (workEstimatorType == null) { + if ((timingData.getWorkEstimator() != null) && (timingData.getWorkEstimator().length() > 0)) { + labels.add(new Label(timingData.getWorkEstimator() + " could not be resolved", ERROR_IMAGE)); + } + return labels; + } + try { + boolean implementsOk = isImplementer(workEstimatorType, WorkEstimatorSelectingCellEditor.WORK_ESTIMATOR_CLASSNAME); + if (!implementsOk) { + IType[] superClasses = workEstimatorType.newSupertypeHierarchy(null) + .getAllSuperclasses(workEstimatorType); + for (int i = 0; i < superClasses.length; i++) { + if (isImplementer(superClasses[i], WorkEstimatorSelectingCellEditor.WORK_ESTIMATOR_CLASSNAME)) { + implementsOk = true; + break; + } + } + } + if (!implementsOk) { + labels.add(new Label(timingData.getWorkEstimator() + " doesn't implement " + WorkEstimatorSelectingCellEditor.WORK_ESTIMATOR_CLASSNAME, ERROR_IMAGE)); + } + } catch (JavaModelException e) { + labels.add(new Label(timingData.getWorkEstimator() + " doesn't contain enough information or has unknown error", ERROR_IMAGE)); + } + return labels; + } + + /** + * Determine whether a particular IType implements a particular interface + * @param theType the IType to check + * @param implString the name of the interface to check (package qualified string) + * @return true iff theType implements implString + * @throws JavaModelException if resolution fails for a serious reason + */ + private boolean isImplementer(IType theType, String implString) throws JavaModelException + { + String[] impls = theType.getSuperInterfaceNames(); + for (int i = 0; i < impls.length; i++) { + if (impls[i].equals(implString)) { + return true; + } + String impl = getUniqueTypeResolution(impls[i], theType); + if (impl.equals(implString)) { + return true; + } + } + return false; + } + + /** + * Get the unique resolution of a possibly simple type name in the context of a type declaration + * @param toResolve the possibly simple name to resolve + * @param context the type declaration whose imports, etc are the context of the resolution + * @return the fully qualified type name resulting from the resolution or "" if either (1) + * the resolution fails, or (2) the resolution does not produce a unique answer. + */ + private String getUniqueTypeResolution(String toResolve, IType context) + { + String[][] resolves; + try { + resolves = context.resolveType(toResolve); + } catch (JavaModelException e) { + return ""; + } + if (resolves == null || resolves.length != 1) { + return ""; + } + if (resolves[0][0].length() == 0) { + /* default package */ + return resolves[0][1]; + } + return resolves[0][0] + "." + resolves[0][1]; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.ModelElement#getParent() + */ + @Override + public void setParent(TaskDiagram parent) { + super.setParent(parent); + parent.addPropertyChangeListener(this); + } + + /* (non-Javadoc) + * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) + */ + public void propertyChange(PropertyChangeEvent evt) { + String prop = evt.getPropertyName(); + + if (prop.equals(TaskDiagram.CHILD_ADDED_PROP)) { + if (evt.getNewValue() != null) { + if (evt.getNewValue() instanceof NormalTask) + ((ModelElement) evt.getNewValue()).addPropertyChangeListener(this); + else if (!(evt.getNewValue() instanceof StreamBasedGlobalTiming)) { + /* Display error message */ + String[] buttonLabels = new String[] {"Ok"}; + String message = "With the stream-based timing grammar only normal tasks are allowed."; + MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Illegal Task!", + null, message, MessageDialog.ERROR, buttonLabels, 2); + dialog.open(); + } + } + } + else if (prop.equals(TaskDiagram.CHILD_REMOVED_PROP)) { + if ((evt.getNewValue() != null) && + (evt.getNewValue() instanceof NormalTask)) { + ((ModelElement) evt.getNewValue()).removePropertyChangeListener(this); + } + } + else if (prop.equals(Task.SOURCE_CONNECTIONS_PROP)) { + if (evt.getNewValue() != null) { + if (evt.getNewValue() instanceof Connection) { + Connection conn = (Connection) evt.getNewValue(); + //conn.setSourcePortBuffering(true); + //conn.setTargetPortBuffering(true); + conn.addPropertyChangeListener(this); + } + } + else if (evt.getOldValue() != null) { + if (evt.getOldValue() instanceof Connection) + ((ModelElement) evt.getOldValue()).removePropertyChangeListener(this); + } + } + else if (prop.equals(Connection.PORT_DECLARATION_CHANGED_PROP)) { + if ((evt.getNewValue() != null) && + (evt.getNewValue() instanceof PortDeclaration)) { + + Connection conn = (Connection) evt.getSource(); + if (conn.getSource() instanceof NormalTask) { + NormalTask sourceTask = (NormalTask) conn.getSource(); + sourceTask.setTiming(sourceTask.getTiming()); + } + if (conn.getTarget() instanceof NormalTask) { + NormalTask targetTask = (NormalTask) conn.getTarget(); + targetTask.setTiming(targetTask.getTiming()); + } + } + } + else if ((prop.equals(Connection.SOURCE_PORT_BUFFERING_PROP)) || + (prop.equals(Connection.TARGET_PORT_BUFFERING_PROP))) { + if ((evt.getNewValue() != null) && + (evt.getNewValue() instanceof Boolean)) { + Connection conn = (Connection) evt.getSource(); + conn.setTiming(conn.getTiming()); + } + } + } +} Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGrammarProvider.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGrammarProvider.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedGrammarProvider.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,61 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.timing.streaming; + +import com.ibm.realtime.flexotask.editor.model.AbstractLibraryProvider; +import com.ibm.realtime.flexotask.editor.model.GlobalTiming; +import com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser; +import com.ibm.realtime.flexotask.timing.streaming.StreamBasedGlobalTimingData; +import com.ibm.realtime.flexotask.timing.streaming.StreamBasedTimingDataParser; + +public class StreamBasedGrammarProvider extends AbstractLibraryProvider implements TimingGrammarProvider { + // @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getDescription() + public String getDescription() { + return "Use stream-based timing grammar with rates"; + } + + // @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getGlobalTiming(com.ibm.realtime.flexotask.timing.FlexotaskTimingData) + public GlobalTiming getGlobalTiming(FlexotaskTimingData annotation) { + if (annotation instanceof StreamBasedGlobalTimingData) + return new StreamBasedGlobalTiming((StreamBasedGlobalTimingData) annotation); + return null; + } + + // @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getLabel() + public String getLabel() { + return "Stream-based Timing"; + } + + // @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getParser() + public FlexotaskTimingDataParser getParser() { + return new StreamBasedTimingDataParser(); + } + + // @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getTemplateClass() + public Class<? extends GlobalTiming> getTemplateClass() { + return StreamBasedGlobalTiming.class; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.AbstractLibraryProvider#getPluginID() + */ + public String getPluginID() + { + return FlexotaskStreamingPlugin.PLUGIN_ID; + } +} Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedLocalTiming.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedLocalTiming.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/StreamBasedLocalTiming.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,346 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.timing.streaming; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.draw2d.Label; +import org.eclipse.ui.views.properties.ComboBoxPropertyDescriptor; +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.PropertyDescriptor; + +import com.ibm.realtime.flexotask.editor.dialogs.streaming.TaskIORatePropertyDescriptor; +import com.ibm.realtime.flexotask.editor.model.Category; +import com.ibm.realtime.flexotask.editor.model.Connection; +import com.ibm.realtime.flexotask.editor.model.LocalTiming; +import com.ibm.realtime.flexotask.editor.model.ModelElement; +import com.ibm.realtime.flexotask.editor.model.NormalTask; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.streaming.FlexotaskTaskPortMuxMode; +import com.ibm.realtime.flexotask.timing.streaming.StreamBasedTimingAnnotation; + +/** + * The local annotator for all tasks under the stream-based grammar. + */ +public class StreamBasedLocalTiming implements LocalTiming { + /** Error message */ + private static final Label multiplePortsErrorLabel = new Label("Task cannot have multiple input and output ports", ModelElement.ERROR_IMAGE); + + /** Error message */ + private static final Label unbufferedPortsErrorLabel = new Label("All ports are required to be buffered", ModelElement.ERROR_IMAGE); + + /** The property ID for task pop rate */ + private static final String TASK_POP_RATE = "StreamBasedLocalTimingTaskPopRate"; + + /** The property ID for task peek rate */ + private static final String TASK_PEEK_RATE = "StreamBasedLocalTimingTaskPeekRate"; + + /** The property ID for task push rate */ + private static final String TASK_PUSH_RATE = "StreamBasedLocalTimingTaskPushRate"; + + /** The property ID for task output port mode */ + private static final String TASK_OUTPUT_PORT_MUX_MODE = "StreamBasedLocalTimingTaskOutputPortMuxMode"; + + /** The property ID for task state mode */ + private static final String TASK_STATE_MODE = "StreamBasedLocalTimingTaskStateMode"; + + /** String enumerator for when task state modes */ + private static final String[] TASK_STATE_MODES = { "stateless", "stateful" }; + + /** The editor-friendly names for the output port modes, in the same order as previous */ + private static final String[] taskOutputPortModeEditorNames = { + "uniform round-robin", "duplicate" }; + + /** The annotation */ + private StreamBasedTimingAnnotation annotation = new StreamBasedTimingAnnotation(); + + /** The model element */ + private ModelElement element; + + /** + * Constructor. + * @param element + */ + public StreamBasedLocalTiming(ModelElement element) { + this.element = element; + } + + // @see com.ibm.realtime.flexotask.editor.model.ModelElement#getToolTipLabels(java.util.List) + public void getToolTipLabels(List<Label> labels) { + if (annotation == null) { + Label label = new Label(ModelElement.OK_IMAGE); + label.setText("No timing offsets"); + } + else { + if (element instanceof NormalTask) { + if (numberOfInputPorts((NormalTask) element) > 0) { + Label label = new Label(ModelElement.OK_IMAGE); + if ((annotation.getTaskPopRate() == null) || + (!annotation.getTaskPopRate().isSpecified())) { + label.setIcon(ModelElement.WARNING_IMAGE); + label.setText("No task pop rate"); + } else { + label.setText("Task pop rate=" + + annotation.getTaskPopRate()); + } + labels.add(label); + + label = new Label(ModelElement.OK_IMAGE); + if ((annotation.getTaskPeekRate() == null) || (!annotation.getTaskPeekRate().isSpecified())) { + label.setText("No task peek rate"); + } else { + label.setText("Task peek rate=" + + annotation.getTaskPeekRate()); + } + labels.add(label); + } + + if ((numberOfOutputPorts((NormalTask) element) > 0)) { + Label label = new Label(ModelElement.OK_IMAGE); + if ((annotation.getTaskPushRate() == null) || + (!annotation.getTaskPushRate().isSpecified())) { + label.setIcon(ModelElement.WARNING_IMAGE); + label.setText("No task push rate"); + } else { + label.setText("Task push rate=" + + annotation.getTaskPushRate()); + } + labels.add(label); + + if (((NormalTask) element).getOutgoingConnections().size() > 1) { + label = new Label(ModelElement.OK_IMAGE); + if (annotation.getTaskOutputPortMode() == null) { + label.setText("No output port multiplex mode"); + } else { + FlexotaskTaskPortMuxMode portMode = annotation.getTaskOutputPortMode(); + int i = 0; + if (portMode != null) + i = portMode.asIndex(); + label.setText("Output port multiplex mode=" + + taskOutputPortModeEditorNames[i]); + } + labels.add(label); + } + } + } + } + + if (element instanceof NormalTask) { + if ((numberOfInputPorts((NormalTask) element) > 1) || + (numberOfOutputPorts((NormalTask) element) > 1)) + labels.add(multiplePortsErrorLabel); + else + labels.remove(multiplePortsErrorLabel); + } + + if (element instanceof Connection) { + if (((Connection) element).getSourcePortBuffering() && + ((Connection) element).getTargetPortBuffering()) + labels.remove(unbufferedPortsErrorLabel); + else + labels.add(unbufferedPortsErrorLabel); + } + } + + /** + * Loops through the input ports of the provided task and returns the number + * of unique port names used by the task. + * @param task the task. + * @return the number of unique input port names used by the task. + */ + private int numberOfInputPorts(NormalTask task) { + Set ports = new HashSet(); + for (Iterator<Connection> i = task.getIncomingConnections().iterator(); i.hasNext(); ) { + Connection conn = i.next(); + ports.add(conn.getTargetPortName()); + } + return ports.size(); + } + + + /** + * Loops through the output ports of the provided task and returns the number + * of unique port names used by the task. + * @param task the task. + * @return the number of unique output port names used by the task. + */ + private int numberOfOutputPorts(NormalTask task) { + Set ports = new HashSet(); + for (Iterator<Connection> i = task.getOutgoingConnections().iterator(); i.hasNext(); ) { + Connection conn = i.next(); + ports.add(conn.getSourcePortName()); + } + return ports.size(); + } + + + // @see com.ibm.realtime.flexotask.editor.model.GlobalTiming#getAnnotation() + public FlexotaskTimingData getAnnotation() { + return annotation; + } + + // @see com.ibm.realtime.flexotask.editor.model.GlobalTiming#setAnnotation(com.ibm.realtime.flexotask.timing.FlexotaskTimingData) + public void setAnnotation(FlexotaskTimingData annotation) { + this.annotation = (StreamBasedTimingAnnotation) annotation; + } + + // @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() + public IPropertyDescriptor[] getPropertyDescriptors() { + List<IPropertyDescriptor> propertyList = new ArrayList<IPropertyDescriptor>(); + PropertyDescriptor pd = null; + if ((element instanceof NormalTask) && + (((NormalTask) element).getIncomingConnections().size() > 0)) { + pd = new TaskIORatePropertyDescriptor(TASK_POP_RATE, "Task Pop Rate"); + pd.setCategory(Category.INPUT_CATEGORY); + propertyList.add(pd); + pd = new TaskIORatePropertyDescriptor(TASK_PEEK_RATE, "Task Peek Rate"); + pd.setCategory(Category.INPUT_CATEGORY); + propertyList.add(pd); + } + if ((element instanceof NormalTask) && + (((NormalTask) element).getOutgoingConnections().size() > 0)) { + pd = new TaskIORatePropertyDescriptor(TASK_PUSH_RATE, "Task Push Rate"); + pd.setCategory(Category.OUTPUT_CATEGORY); + propertyList.add(pd); + pd = new ComboBoxPropertyDescriptor(TASK_STATE_MODE, "Task State Mode", TASK_STATE_MODES ); + pd.setCategory(Category.BASIC_CATEGORY); + propertyList.add(pd); + if (((NormalTask) element).getOutgoingConnections().size() > 1) { + pd = new ComboBoxPropertyDescriptor(TASK_OUTPUT_PORT_MUX_MODE, "Task Output Port Multiplexing Mode", taskOutputPortModeEditorNames); + pd.setCategory(Category.OUTPUT_CATEGORY); + propertyList.add(pd); + } + } + return propertyList.toArray(new IPropertyDescriptor[0]); + } + + // @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) + public Object getPropertyValue(Object id) { + if (TASK_POP_RATE.equals(id)) { + if (annotation.getTaskPopRate().isSpecified()) + return annotation.getTaskPopRate().toString(); + return null; + } + else if (TASK_PEEK_RATE.equals(id)) { + if (annotation.getTaskPeekRate().isSpecified()) + return annotation.getTaskPeekRate().toString(); + return null; + } + else if (TASK_PUSH_RATE.equals(id)) { + if (annotation.getTaskPushRate().isSpecified()) + return annotation.getTaskPushRate().toString(); + return null; + } + else if (TASK_OUTPUT_PORT_MUX_MODE.equals(id)) { + FlexotaskTaskPortMuxMode mode = annotation.getTaskOutputPortMode(); + if (mode != null) + return mode.asIndex(); + return null; + } + else if (TASK_STATE_MODE.equals(id)) + return new Integer(annotation.getTaskIsStateless() ? 0 : 1); + else + return null; + } + + // @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) + public boolean isPropertySet(Object id) { + if (TASK_POP_RATE.equals(id)) + return annotation.getTaskPopRate().isSpecified(); + else if (TASK_PEEK_RATE.equals(id)) + return annotation.getTaskPeekRate().isSpecified(); + else if (TASK_PUSH_RATE.equals(id)) + return annotation.getTaskPushRate().isSpecified(); + else if (TASK_OUTPUT_PORT_MUX_MODE.equals(id)) + return true; + else if (TASK_STATE_MODE.equals(id)) + return annotation.getTaskIsStateless(); + else + return false; + } + + // @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) + public void resetPropertyValue(Object id) { + if (TASK_POP_RATE.equals(id)) + setTaskInputRate(null); + else if (TASK_PEEK_RATE.equals(id)) + setTaskInputRate(null); + else if (TASK_PUSH_RATE.equals(id)) + setTaskOutputRate(null); + else if (TASK_OUTPUT_PORT_MUX_MODE.equals(id)) + setTaskOutputPortMode(null); + else if (TASK_STATE_MODE.equals(id)) + setTaskStateMode(false); + } + + // @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) + public void setPropertyValue(Object id, Object value) { + if (TASK_POP_RATE.equals(id)) + setTaskInputRate((String) value); + else if (TASK_PEEK_RATE.equals(id)) + setTaskInputPeekRate((String) value); + else if (TASK_PUSH_RATE.equals(id)) + setTaskOutputRate((String) value); + else if (TASK_OUTPUT_PORT_MUX_MODE.equals(id)) + setTaskOutputPortMode((Integer) value); + else if (TASK_STATE_MODE.equals(id)) + setTaskStateMode(((Integer) value).intValue() == 0); + } + + // @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() + public Object getEditableValue() { + return this; + } + + private void setTaskOutputPortMode(Integer value) { + annotation.setTaskOutputPortMode(FlexotaskTaskPortMuxMode.getTaskPortMode(value)); + } + + private void setTaskInputRate(String value) { + try { + annotation.setTaskPopRate(value); + } + catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } + + private void setTaskInputPeekRate(String value) { + try { + annotation.setTaskPeekRate(value); + } + catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } + + private void setTaskOutputRate(String value) { + try { + annotation.setTaskPushRate(value); + } + catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } + + private void setTaskStateMode(boolean isStateless) { + annotation.setTaskIsStateless(isStateless); + } +} Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorPropertyDescriptor.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorPropertyDescriptor.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorPropertyDescriptor.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,37 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.timing.streaming; + +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.swt.widgets.Composite; + +import com.ibm.realtime.flexotask.editor.dialogs.ClassPropertyDescriptor; +import com.ibm.realtime.flexotask.editor.model.GlobalTiming; + +public class WorkEstimatorPropertyDescriptor extends ClassPropertyDescriptor { + + private GlobalTiming globalTiming; + public WorkEstimatorPropertyDescriptor(Object id, String displayName, GlobalTiming globalTiming) { + super(id, displayName, null); + this.globalTiming = globalTiming; + } + + // @see org.eclipse.ui.views.properties.PropertyDescriptor#createPropertyEditor(org.eclipse.swt.widgets.Composite) + public CellEditor createPropertyEditor(Composite parent) + { + return new WorkEstimatorSelectingCellEditor(parent, globalTiming); + } +} Added: trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorSelectingCellEditor.java =================================================================== --- trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorSelectingCellEditor.java (rev 0) +++ trunk/flexotask-streaming/src/com/ibm/realtime/flexotask/editor/timing/streaming/WorkEstimatorSelectingCellEditor.java 2009-04-12 15:46:57 UTC (rev 150) @@ -0,0 +1,196 @@ +/* +* This file is part of Flexible Task Graphs +* (http://sourceforge.net/projects/flexotasks) +* +* Copyright (c) 2006 - 2008 IBM Corporation and Ecole Polytechnique +* Federale de Lausanne (EPFL). +* 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: +* IBM Corporation +* EPFL +*/ +package com.ibm.realtime.flexotask.editor.timing.streaming; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.ui.IJavaElementSearchConstants; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jdt.ui.actions.OpenNewClassWizardAction; +import org.eclipse.jdt.ui.wizards.NewClassWizardPage; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.SelectionDialog; + +import com.ibm.realtime.flexotask.editor.FlexotaskEditor; +import com.ibm.realtime.flexotask.editor.dialogs.ClassSelectingCellEditor; +import com.ibm.realtime.flexotask.editor.model.GlobalTiming; + +/** + * A specialization of the class selecting cell editor which filters out and + * displays only classes for selection that implement the interface required + * for work estimate classes. + */ +public class WorkEstimatorSelectingCellEditor extends ClassSelectingCellEditor { + static final String WORK_ESTIMATOR_CLASSNAME = "at.dms.kjc.sir.lowering.partition.WorkEstimate.WorkVisitorIntf"; + /** Determines whether to offer the create dialog or the source dialog */ + private boolean useCreate; + /** Remember actual value last set for use in some dialogs */ + private Object lastValue; + /** The global timing of the graph specification */ + private GlobalTiming globalTiming; + + /** + * Constructor + * @param parent + * @param globalTiming the global timing of the graph specification + */ + public WorkEstimatorSelectingCellEditor(Composite parent, GlobalTiming globalTiming) { + super(parent); + this.globalTiming = globalTiming; + } + + // @see com.ibm.realtime.flexotask.editor.model.ClassSelectingCellEditor#doSetValue(java.lang.Object) + protected void doSetValue(Object value) + { + super.doSetValue(value); + useCreate = (value == null || value.toString().length() == 0); + lastValue = value; + } + + /** + * A class selection dialog that filters out and displays only classes found + * in the workspace that implements the interface needed in order to implement + * a work estimator class + * @param cellEditorWindow + * @return + */ + private Object openFilteringClassSelectionDialogBox(Control cellEditorWindow) + { + SelectionDialog dialog; + try { + dialog = JavaUI.createTypeDialog( + cellEditorWindow.getShell(), new ProgressMonitorDialog(null), + SearchEngine.createWorkspaceScope(), + IJavaElementSearchConstants.CONSIDER_CLASSES, false); + } catch (JavaModelException e) { + return null; + } + dialog.setTitle("Work Estimator Class selection"); + dialog.setMessage("Select a Work Estimator class"); + if (dialog.open() == IDialogConstants.CANCEL_ID) + return null; + + Object[] types= dialog.getResult(); + if (types == null || types.length == 0) + return null; + return new ClassWrapper((IType)types[0]); + } + + // @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control) + protected Object openDialogBox(Control cellEditorWindow) + { + String[] buttonLabels = useCreate ? new String[] {"Create", "Find"} : + new String[] {"Edit Source", "Find Replacement", "Remove", "Cancel"}; + String promptMessage = useCreate ? + "You can either create a new implementation from the model or find an existing implementation" : + "You can either edit the existing implementation or find an existing implementation to " + + "replace it"; + MessageDialog prompt = new MessageDialog(cellEditorWindow.getShell(), + "Choose strategy", null, promptMessage, MessageDialog.QUESTION, buttonLabels, 0); + int choice = prompt.open(); + if (choice == 0) { + /* create */ + if (useCreate) { + return openCreateDialog(cellEditorWindow.getShell()); + } else { + FlexotaskEditor.openSource(((ClassWrapper) getValue()).classType); + return lastValue; + } + } else if (choice == 1){ + /* find */ + return openFilteringClassSelectionDialogBox(cellEditorWindow); + } else if (choice == 2){ + /* remove */ + return new ClassWrapper(null); + } else { + /* cancelled */ + return lastValue; + } + } + + /** + * Open a class creation dialog that both generates new class source and returns the new + * class as an ClassWrapper + * @param the shell to use if an error dialog is needed + * @return a new ClassWrapper or null if cancelled + */ + private ClassWrapper openCreateDialog(Shell shell) + { + OpenNewClassWizardAction action = new OpenNewClassWizardAction(); + NewClassWizardPage page = new NewClassWizardPage(); + IJavaElement javaElement = JavaCor... [truncated message content] |