Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add graphical support to define parameters with sirius #108

Open
wants to merge 3 commits into
base: 2.0.0_stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions plugins/de.fraunhofer.ipa.ros.sirius/description/ros.odesign
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ownedRepresentations xsi:type="description_1:DiagramDescription" name="Artifact diagram" domainClass="ros::Artifact" enablePopupBars="true">
<metamodel href="../../de.fraunhofer.ipa.ros/model/ros.ecore#/"/>
<defaultLayer name="Default">
<containerMappings name="Node" semanticCandidatesExpression="feature:eAllContents" domainClass="ros::Node">
<containerMappings name="Node" semanticCandidatesExpression="feature:eAllContents" domainClass="ros::Node" childrenPresentation="List">
<borderedNodeMappings name="RosPublisher" semanticCandidatesExpression="feature:eAllContents" domainClass="ros::Publisher">
<style xsi:type="style:SquareDescription" labelSize="10" showIcon="false" tooltipExpression="Topic" resizeKind="NSEW" width="2" height="2">
<borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
Expand Down Expand Up @@ -71,8 +71,8 @@
<color xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_green']"/>
</style>
</borderedNodeMappings>
<subNodeMappings name="ParametersNode" semanticCandidatesExpression="feature:parameter" domainClass="ros::Parameter">
<style xsi:type="style:WorkspaceImageDescription" labelSize="10" showIcon="false" iconPath="/de.fraunhofer.ipa.ros.sirius/icons/parameters.png" tooltipExpression="ComponentParameters" sizeComputationExpression="5" resizeKind="NSEW" workspacePath="/de.fraunhofer.ipa.ros.sirius/icons/parameters_scale.png">
<subNodeMappings name="ParametersNode" semanticCandidatesExpression="feature:parameter" doubleClickDescription="//@ownedViewpoints[name='component']/@ownedRepresentations[name='Artifact%20diagram']/@defaultLayer/@toolSections.0/@ownedTools[name='ParametersConfiguratorDoubleClick']" synchronizationLock="true" domainClass="ros::Parameter">
<style xsi:type="style:WorkspaceImageDescription" borderSizeComputationExpression="2" labelSize="10" iconPath="/de.fraunhofer.ipa.ros.sirius/icons/parameters.png" labelAlignment="LEFT" tooltipExpression="ComponentParameters" hideLabelByDefault="true" sizeComputationExpression="5" resizeKind="NSEW" workspacePath="/de.fraunhofer.ipa.ros.sirius/icons/parameters_scale.png">
<borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
<labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
</style>
Expand Down Expand Up @@ -199,6 +199,16 @@
</initialOperation>
</ownedTools>
<ownedTools xsi:type="tool_1:ExternalJavaAction" name="NewParameter" id="de.fraunhofer.ipa.ros.sirius.javaActionsNewParameter"/>
<!--ownedTools xsi:type="tool:DoubleClickDescription" name="ParametersConfiguratorDoubleClick" mappings="//@ownedViewpoints[name='component']/@ownedRepresentations[name='Artifact%20diagram']/@defaultLayer/@containerMappings[name='Node']/@subNodeMappings[name='ParametersNode']">
<element name="element"/>
<elementView name="elementView"/>
<initialOperation>
<firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:element">
<subModelOperations xsi:type="tool_1:ExternalJavaActionCall" name="Parameter Configurator" forceRefresh="true" elementsToSelect="var:element" icon="/de.fraunhofer.ipa.ros.sirius/icons/parameters_scale.png" action="//@ownedViewpoints[name='component']/@ownedRepresentations[name='Artifact%20diagram']/@defaultLayer/@toolSections.0/@ownedTools[name='ParameterEditor']"/>
</firstModelOperations>
</initialOperation>
</ownedTools>
<ownedTools xsi:type="tool_1:ExternalJavaAction" name="ParameterEditor" elementsToSelect="var:self" id="de.fraunhofer.ipa.ros.sirius.javaActionsParameterEditor"/-->
</toolSections>
</defaultLayer>
</ownedRepresentations>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,40 @@

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.sirius.tools.api.ui.IExternalJavaAction;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.ElementListSelectionDialog;

import ros.Parameter;
import ros.ParameterBoolean;
import ros.ParameterStringType;
import ros.ParameterType;
import ros.impl.ParameterBooleanImpl;
import ros.impl.ParameterArrayTypeImpl;
import ros.impl.ParameterBase64TypeImpl;
import ros.impl.ParameterBooleanTypeImpl;
import ros.impl.ParameterDateTypeImpl;
import ros.impl.ParameterDoubleTypeImpl;
import ros.impl.ParameterImpl;
import ros.impl.ParameterIntegerTypeImpl;
import ros.impl.ParameterStringImpl;
import ros.impl.ParameterStringTypeImpl;
import ros.impl.ParameterTypeImpl;


public class ExternalJavaActionNewParameter implements IExternalJavaAction {

public IFile modelFile;
protected IWorkbench workbench;
protected IStructuredSelection selection;
//public static final List<String> FILE_EXTENSIONS = Collections.unmodifiableList(Arrays.asList(ComponentInterfaceEditorPlugin.INSTANCE.getString("_UI_ComponentInterfaceEditorFilenameExtensions").split("\\s*,\\s*")));
protected ExecutionEvent event;
EList<ParameterType> subtypes;
EList<String> subtypes_;
EList<Combo> combos;
EList<String> subtypes_string;


public ExternalJavaActionNewParameter() {
// TODO Auto-generated constructor stub
Expand All @@ -60,28 +61,99 @@ public void execute(Collection<? extends EObject> arg0, Map<String, Object> arg1
Parameter param = param_collection.iterator().next();
ParameterType type = null;

dlg.setElements( new Object[] {"Boolean","String","Integer","Date","Double"});
dlg.setElements( new Object[] {"Boolean","String","Integer","Double","Base64", "Array"});/** "List","Struc","Date"*/
dlg.open();

Object selected_type = dlg.getFirstResult();
if (selected_type.toString() == "Boolean") {
type = GetSelectedType(selected_type.toString(), activeShell);
/**if (selected_type.toString() == "List") {
type = new ParameterListTypeImpl();
}
if (selected_type.toString() == "Struc") {
type = new ParameterStructTypeImpl();
}*/
param.setType(type);
}

@SuppressWarnings("null")
public ParameterType GetSelectedType(String selected_type, Shell activeShell) {
ParameterType type = null;
if (selected_type== "Boolean") {
type = new ParameterBooleanTypeImpl();
}
if (selected_type.toString() == "String") {
if (selected_type == "String") {
type = new ParameterStringTypeImpl();
}
if (selected_type.toString() == "Integer") {
if (selected_type == "Integer") {
type = new ParameterIntegerTypeImpl();
}
if (selected_type.toString() == "Date") {
/**if (selected_type == "Date") {
type = new ParameterDateTypeImpl();
}
}*/
if (selected_type.toString() == "Double") {
type = new ParameterDoubleTypeImpl();
}
param.setType(type);
if (selected_type.toString() == "Base64") {
type = new ParameterBase64TypeImpl();
}
if (selected_type.toString() == "Array") {
ParameterType subtype = null;
type = new ParameterArrayTypeImpl();
ElementListSelectionDialog dlg = new ElementListSelectionDialog(activeShell, new LabelProvider());
dlg.setTitle("ArraySubtype");
dlg.setMessage("Select a type for the elements of your Array:");
dlg.setElements( new Object[] {"Boolean","String","Integer","Date","Double","Base64", "List", "Array","Struc"});
dlg.open();
Object selected_subtype = dlg.getFirstResult();
subtype = GetSelectedType(selected_subtype.toString(), activeShell);
((ParameterArrayTypeImpl) type).setType(subtype);
}
/**if (selected_type.toString() == "List") {
EList<Combo> combos = null;
type = new ParameterListTypeImpl();

InputDialog dlg = new InputDialog(activeShell, "Lenght of the list parameter", null, "2",null);
int lenght = 0;
if (dlg.open() == 0) {
String param = dlg.getValue();
try {
lenght = Integer.parseInt(param);
} catch (NumberFormatException e){
lenght = 1;
}
}
for (int i=1;i<lenght+1;i++) {
subtypes.add(GetSelectedType("String",activeShell));
}

GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
activeShell.setLayout(gridLayout);
new Label(activeShell, SWT.NULL).setText("List parameter definition: ");
Combo combo = new Combo(activeShell, SWT.DOWN);

}
for (int i=1;i<lenght+1;i++) {
String items[] = { "Boolean","String","Integer","Date","Double","Base64"};
GridData gridData = new GridData(GridData.CENTER);
gridData.horizontalSpan = 1;
new Label(activeShell, SWT.NULL).setText("Type element "+ i +" :");
combo.setItems(items);
combo.setLayoutData(gridData);
activeShell.pack();
activeShell.open();
}

while (!activeShell.isDisposed()) {
if (!activeShell.getDisplay().readAndDispatch ())
activeShell.getDisplay().sleep ();
}

for (int i=0; i<subtypes.size(); i++) {
((ParameterListTypeImpl) type).getSequence().add(subtypes.get(i));
}
}*/

return type;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package de.fraunhofer.ipa.ros.sirius;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.sirius.tools.api.ui.IExternalJavaAction;
import org.eclipse.sirius.viewpoint.DView;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;

import ros.Parameter;
import ros.impl.NodeImpl;



public class ParametersView implements IExternalJavaAction {

public IFile modelFile;
protected IWorkbench workbench;
protected IStructuredSelection selection;
protected ExecutionEvent event;

public ParametersView() {
// TODO Auto-generated constructor stub
}

@Override
public boolean canExecute(Collection<? extends EObject> arg0) {
// TODO Auto-generated method stub
return true;
}

@Override
public void execute(Collection<? extends EObject> arg0, Map<String, Object> arg1) {
for (EObject diagram : arg0) {
List<DView> owned_views = ConnectionsCheckUtils.getDiagramViews(diagram);
for (DView view : owned_views) {
for (EObject rossystemEObj : view.getModels()) {
NodeImpl rosnode = ((NodeImpl)rossystemEObj);
System.out.println(rosnode.getParameter());
}
}}
Display display = Display.getDefault();
Shell activeShell = display.getActiveShell();
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println(arg0.toString());
System.out.println(arg1.toString());

/**ParametersWizard wizard = new ParametersWizard();
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(), arg0, arg1);
WizardDialog dialog = new WizardDialog(activeShell,wizard);
dialog.create();
dialog.getShell().setText(wizard.getWindowTitle());
dialog.open();*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package de.fraunhofer.ipa.ros.sirius;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardSelectionPage;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.viewpoint.DAnalysis;
import org.eclipse.sirius.viewpoint.DView;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.actions.WorkspaceModifyOperation;

import componentInterface.ComponentInterface;
import componentInterface.RosActionClient;
import componentInterface.RosActionServer;
import componentInterface.RosParameter;
import componentInterface.RosPublisher;
import componentInterface.RosServiceClient;
import componentInterface.RosServiceServer;
import componentInterface.RosSubscriber;
import componentInterface.impl.RosActionClientImpl;
import componentInterface.impl.RosActionServerImpl;
import componentInterface.impl.RosParameterImpl;
import componentInterface.impl.RosPublisherImpl;
import componentInterface.impl.RosServiceClientImpl;
import componentInterface.impl.RosServiceServerImpl;
import componentInterface.impl.RosSubscriberImpl;
import ros.ActionClient;
import ros.ActionServer;
import ros.Artifact;
import ros.Node;
import ros.Package;
import ros.PackageSet;
import ros.Publisher;
import ros.ServiceClient;
import ros.ServiceServer;
import ros.Subscriber;
import ros.Parameter;
import rossystem.RosSystem;

/**
* This is a simple wizard for creating a new model file.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class ParametersWizard extends Wizard implements INewWizard {

protected IStructuredSelection selection;
protected IWorkbench workbench;
public FileDialog fDialog;
public String ComponentName;
public String ComponentNameSpace;
public String NameSpaceInterfaces;
//public ComponentInterface CI_input;
public IProject project;
public EObject eobject;


public void init(IWorkbench workbench, IStructuredSelection selection, Collection<? extends EObject> node, Map<String, Object> nameSpace) {
this.workbench = workbench;
this.selection = selection;
try {

project = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput().getAdapter(IResource.class).getProject();
setWindowTitle("Ros node parameters");
}finally{

}
}

@Override
public boolean performFinish() {
try {


WorkspaceModifyOperation operation =
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor progressMonitor) {
try {

}catch (Exception exception) {
}
finally {
progressMonitor.done();
}
}};
getContainer().run(false, false, operation);
return true;
}catch (Exception exception) {
return false;
}
}



@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
// TODO Auto-generated method stub

}

}
Loading