From 32e8f3d74b2f665be3ab12ef0301bcd6dc4964bb Mon Sep 17 00:00:00 2001 From: apvrille <ludovic.apvrille@eurecom.fr> Date: Mon, 4 Mar 2019 16:02:43 +0100 Subject: [PATCH] Adding operation for TML Tasks --- src/main/java/tmltranslator/TMLTask.java | 9 ++++ .../tmltranslator/TMLTextSpecification.java | 23 ++++++++- src/main/java/ui/GTMLModeling.java | 5 +- src/main/java/ui/TGCAttributeBox.java | 2 +- src/main/java/ui/ebrdd/EBRDDAttributeBox.java | 2 +- src/main/java/ui/procsd/ProCSDComponent.java | 2 +- src/main/java/ui/tmlcd/TMLAttributeBox.java | 2 +- .../ui/tmlcompd/TMLCPrimitiveComponent.java | 17 ++++++- .../java/ui/tmlcompd/TMLCRecordComponent.java | 2 +- src/main/java/ui/tmldd/TMLArchiArtifact.java | 18 +++---- src/main/java/ui/window/JDialogAttribute.java | 47 +++++++++++++++++-- 11 files changed, 109 insertions(+), 20 deletions(-) diff --git a/src/main/java/tmltranslator/TMLTask.java b/src/main/java/tmltranslator/TMLTask.java index 7a13d56c94..0189fdbacd 100755 --- a/src/main/java/tmltranslator/TMLTask.java +++ b/src/main/java/tmltranslator/TMLTask.java @@ -63,6 +63,7 @@ public class TMLTask extends TMLElement { private Set<TMLEvent> eventsList; private int operationType; private String operation; + private String operationMEC; private boolean isAttacker; public TMLTask(String name, Object referenceToClass, Object referenceToActivityDiagram) { @@ -383,6 +384,14 @@ public class TMLTask extends TMLElement { return operationType; } + public void addOperationMEC(String _operation) { + operationMEC = _operation; + } + + public String getOperationMEC() { + return operationMEC; + } + public void addOperation(String _operation) { operation = _operation; } diff --git a/src/main/java/tmltranslator/TMLTextSpecification.java b/src/main/java/tmltranslator/TMLTextSpecification.java index 1954ae0153..d4dc5ea608 100755 --- a/src/main/java/tmltranslator/TMLTextSpecification.java +++ b/src/main/java/tmltranslator/TMLTextSpecification.java @@ -326,6 +326,7 @@ public class TMLTextSpecification<E> { String sb = ""; for(TMLTask task: tmlm.getTasks()) { sb += "TASK" + SP + task.getName() + CR; + sb += "TASKOP" + SP + task.getOperation() + CR; sb += makeActivity(task); sb += "ENDTASK" + CR2; } @@ -1189,7 +1190,7 @@ public class TMLTextSpecification<E> { // inTaskBehavior = false; if (_split.length != 2) { - error = "A request must be declared with exactly 2 parameters, and not " + (_split.length - 1) ; + error = "A task must be declared with exactly 2 parameters, and not " + (_split.length - 1) ; addError(0, _lineNb, 0, error); return -1; } @@ -1222,6 +1223,26 @@ public class TMLTextSpecification<E> { } // TASK + // TASKOP + if((isInstruction("TASKOP", _split[0]))) { + //An operation is really specified? + + if (!inTask) { + error = "A task operation cannot be declared outside the body of another task"; + addError(0, _lineNb, 0, error); + return -1; + } + + String tmpOp = ""; + + for(int j=1; j<_split.length; j++) { + tmpOp += _split[j]; + + } + task.addOperation(tmpOp); + } + + // ENDTASK if((isInstruction("ENDTASK", _split[0]))) { if (!inTask) { diff --git a/src/main/java/ui/GTMLModeling.java b/src/main/java/ui/GTMLModeling.java index 26fb0b3498..32757d8bb5 100644 --- a/src/main/java/ui/GTMLModeling.java +++ b/src/main/java/ui/GTMLModeling.java @@ -604,6 +604,7 @@ public class GTMLModeling { throw new MalformedTMLDesignException(tmlcpc.getValue() + " msg"); } tmlt = new TMLTask(makeName(tgc, tmlcpc.getValue()), tmlcpc, tmladp); + tmlt.addOperation(tmlcpc.getOperation()); tmlt.setAttacker(tmlcpc.isAttacker()); //TraceManager.addDev("Task added:" + tmlt.getName() + " with tadp=" + tmladp + " major=" + tmladp.getMGUI().getMajorTitle(tmladp)); listE.addCor(tmlt, tgc); @@ -3858,7 +3859,7 @@ public class GTMLModeling { s = artifact.getReferenceTaskName(); ArchUnitMEC mec = artifact.getArchUnitMEC(); int operationType = artifact.getOperationType(); - String operation = artifact.getOperation(); + String operationMEC = artifact.getOperationMEC(); //TraceManager.addDev("1) Trying to get task named:" + s); s = s.replaceAll("\\s", ""); //TraceManager.addDev("2) Trying to get task named:" + s); @@ -3869,7 +3870,7 @@ public class GTMLModeling { if (operationType != -1) { task.addOperationType(operationType); } - task.addOperation(operation); + task.addOperationMEC(operationMEC); node.addMECToHwExecutionNode(mec); map.addTaskToHwExecutionNode(task, (HwExecutionNode) node); } else { diff --git a/src/main/java/ui/TGCAttributeBox.java b/src/main/java/ui/TGCAttributeBox.java index e315ba788f..adba2ecf78 100644 --- a/src/main/java/ui/TGCAttributeBox.java +++ b/src/main/java/ui/TGCAttributeBox.java @@ -196,7 +196,7 @@ public abstract class TGCAttributeBox extends TGCWithoutInternalComponent { public boolean editOndoubleClick(JFrame frame) { String oldValue = value; - JDialogAttribute jda = new JDialogAttribute(myAttributes, forbiddenNames, frame, "Setting " + attributeText + "s of " + father.getValue(), attributeText); + JDialogAttribute jda = new JDialogAttribute(myAttributes, forbiddenNames, frame, "Setting " + attributeText + "s of " + father.getValue(), attributeText, null); setJDialogOptions(jda); // jda.setSize(650, 375); GraphicLib.centerOnParent(jda, 650, 375); diff --git a/src/main/java/ui/ebrdd/EBRDDAttributeBox.java b/src/main/java/ui/ebrdd/EBRDDAttributeBox.java index 7c8bdcbaee..c8627ccffe 100644 --- a/src/main/java/ui/ebrdd/EBRDDAttributeBox.java +++ b/src/main/java/ui/ebrdd/EBRDDAttributeBox.java @@ -211,7 +211,7 @@ public class EBRDDAttributeBox extends TGCWithoutInternalComponent { public boolean editOndoubleClick(JFrame frame) { String oldValue = value; - JDialogAttribute jda = new JDialogAttribute(myAttributes, forbiddenNames, frame, "Setting variables", attributeText); + JDialogAttribute jda = new JDialogAttribute(myAttributes, forbiddenNames, frame, "Setting variables", attributeText, null); setJDialogOptions(jda); // jda.setSize(650, 375); GraphicLib.centerOnParent(jda, 650, 375); diff --git a/src/main/java/ui/procsd/ProCSDComponent.java b/src/main/java/ui/procsd/ProCSDComponent.java index 92b54004f5..ca3ff80655 100755 --- a/src/main/java/ui/procsd/ProCSDComponent.java +++ b/src/main/java/ui/procsd/ProCSDComponent.java @@ -516,7 +516,7 @@ public class ProCSDComponent extends TGCWithInternalComponent implements Swallow if (e.getActionCommand().equals("edit attributes")) { JDialogAttribute dialog = new JDialogAttribute(myAttributes, new LinkedList<TAttribute> (), tdp.getGUI().getFrame(), - "Setting attributes for this component", "Attribute"); + "Setting attributes for this component", "Attribute", null); dialog.addAccess("-"); dialog.addType("Natural"); // must see in GProactiveDesign for bool params diff --git a/src/main/java/ui/tmlcd/TMLAttributeBox.java b/src/main/java/ui/tmlcd/TMLAttributeBox.java index 36bf7407b7..0c77c26167 100755 --- a/src/main/java/ui/tmlcd/TMLAttributeBox.java +++ b/src/main/java/ui/tmlcd/TMLAttributeBox.java @@ -241,7 +241,7 @@ public class TMLAttributeBox extends TGCWithoutInternalComponent { public boolean editOndoubleClick(JFrame frame) { String oldValue = value; - JDialogAttribute jda = new JDialogAttribute(myAttributes, forbiddenNames, frame, "Setting " + attributeText + "s of " + father.getValue(), attributeText); + JDialogAttribute jda = new JDialogAttribute(myAttributes, forbiddenNames, frame, "Setting " + attributeText + "s of " + father.getValue(), attributeText, null); setJDialogOptions(jda); // jda.setSize(650, 375); GraphicLib.centerOnParent(jda, 650, 375); diff --git a/src/main/java/ui/tmlcompd/TMLCPrimitiveComponent.java b/src/main/java/ui/tmlcompd/TMLCPrimitiveComponent.java index 3671d5abf0..c6ffa17757 100755 --- a/src/main/java/ui/tmlcompd/TMLCPrimitiveComponent.java +++ b/src/main/java/ui/tmlcompd/TMLCPrimitiveComponent.java @@ -83,6 +83,8 @@ public class TMLCPrimitiveComponent extends TGCScalableWithInternalComponent imp private int textX = 15; // border for ports private double dtextX = 0.0; + private String operation = ""; + public String oldValue; public TMLCPrimitiveComponent(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { @@ -341,7 +343,7 @@ public class TMLCPrimitiveComponent extends TGCScalableWithInternalComponent imp } // And so -> attributes! - JDialogAttribute jda = new JDialogAttribute(myAttributes, null, frame, "Setting attributes of " + value, "Attribute"); + JDialogAttribute jda = new JDialogAttribute(myAttributes, null, frame, "Setting attributes of " + value, "Attribute", operation); setJDialogOptions(jda); // jda.setSize(650, 375); GraphicLib.centerOnParent(jda, 750, 375); @@ -350,6 +352,7 @@ public class TMLCPrimitiveComponent extends TGCScalableWithInternalComponent imp //if (oldValue.equals(value)) { //return false; //} + operation = jda.getOperation(); rescaled = true; return true; @@ -500,6 +503,8 @@ public class TMLCPrimitiveComponent extends TGCScalableWithInternalComponent imp StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<Data isAttacker=\""); sb.append(isAttacker() ? "Yes" : "No"); + sb.append("\" Operation=\""); + sb.append(operation); sb.append("\" />\n"); for (int i = 0; i < myAttributes.size(); i++) { //TraceManager.addDev("Attribute:" + i); @@ -547,6 +552,12 @@ public class TMLCPrimitiveComponent extends TGCScalableWithInternalComponent imp elt = (Element) n2; if (elt.getTagName().equals("Data")) { isAttacker = elt.getAttribute("isAttacker").equals("Yes"); + String tmpO = elt.getAttribute("Operation"); + if (tmpO == null) { + operation = ""; + } else { + operation = tmpO; + } } if (elt.getTagName().equals("Attribute")) { //TraceManager.addDev("Analyzing attribute"); @@ -651,6 +662,10 @@ public class TMLCPrimitiveComponent extends TGCScalableWithInternalComponent imp return attr; } + public String getOperation() { + return operation; + } + public TMLCPath findPathWith(TGComponent tgc) { return ((TMLComponentTaskDiagramPanel) tdp).findPathWith(tgc); } diff --git a/src/main/java/ui/tmlcompd/TMLCRecordComponent.java b/src/main/java/ui/tmlcompd/TMLCRecordComponent.java index 69bcd04f44..a7118b2456 100755 --- a/src/main/java/ui/tmlcompd/TMLCRecordComponent.java +++ b/src/main/java/ui/tmlcompd/TMLCRecordComponent.java @@ -290,7 +290,7 @@ public class TMLCRecordComponent extends TGCScalableWithInternalComponent implem } // And so -> attributes! - JDialogAttribute jda = new JDialogAttribute(myAttributes, null, frame, "Setting fields of " + value, "Field"); + JDialogAttribute jda = new JDialogAttribute(myAttributes, null, frame, "Setting fields of " + value, "Field", null); setJDialogOptions(jda); // jda.setSize(650, 375); GraphicLib.centerOnParent(jda, 650, 375); diff --git a/src/main/java/ui/tmldd/TMLArchiArtifact.java b/src/main/java/ui/tmldd/TMLArchiArtifact.java index cfb54ea77f..6ae484e6fa 100755 --- a/src/main/java/ui/tmldd/TMLArchiArtifact.java +++ b/src/main/java/ui/tmldd/TMLArchiArtifact.java @@ -71,7 +71,8 @@ public class TMLArchiArtifact extends TGCWithoutInternalComponent implements Swa protected String referenceTaskName = "referenceToTask"; protected String taskName = "name"; protected int priority = 0; // Between 0 and 10 - protected String operation = "VOID"; + protected String operation = ""; + protected String operationMEC = "VOID"; private ArchUnitMEC fatherArchUnitMECType = new CpuMEC(); @@ -185,11 +186,11 @@ public class TMLArchiArtifact extends TGCWithoutInternalComponent implements Swa if (father!=null){ fatherArchUnitMECType = ((TMLArchiNode)father).getMECType(); } - JDialogTMLTaskArtifact dialog = new JDialogTMLTaskArtifact(frame, "Setting artifact attributes", this, operation, fatherArchUnitMECType); + JDialogTMLTaskArtifact dialog = new JDialogTMLTaskArtifact(frame, "Setting artifact attributes", this, operationMEC, fatherArchUnitMECType); // dialog.setSize(400, 350); GraphicLib.centerOnParent(dialog, 400, 350); dialog.setVisible( true ); // blocked until dialog has been closed - operation = dialog.getOperation(); + operationMEC = dialog.getOperation(); if (!dialog.isRegularClose()) { return false; @@ -250,8 +251,8 @@ public class TMLArchiArtifact extends TGCWithoutInternalComponent implements Swa sb.append( referenceTaskName ); sb.append( "\" priority=\"" ); sb.append( priority ); - sb.append( "\" operation=\"" ); - sb.append( operation ); + sb.append( "\" operationMEC=\"" ); + sb.append( operationMEC ); sb.append( "\" fatherComponentMECType=\"" + fatherArchUnitMECType.getIndex() ); sb.append( "\" />\n" ); sb.append( "</extraparam>\n" ); @@ -288,7 +289,7 @@ public class TMLArchiArtifact extends TGCWithoutInternalComponent implements Swa if (elt != null) { priority = Integer.decode(prio).intValue(); } - operation = elt.getAttribute("operation"); + operationMEC = elt.getAttribute("operationMEC"); if( (elt.getAttribute("fatherComponentMECType") != null) && (elt.getAttribute("fatherComponentMECType").length() > 0) ) { if( elt.getAttribute("fatherComponentMECType").length() > 1 ) { fatherArchUnitMECType = ArchUnitMEC.Types.get(0); @@ -347,10 +348,11 @@ public class TMLArchiArtifact extends TGCWithoutInternalComponent implements Swa return "Priority = " + priority; } - public String getOperation() { - return operation; + public String getOperationMEC() { + return operationMEC; } + public int getOperationType() { if( fatherArchUnitMECType instanceof FepMEC ) { diff --git a/src/main/java/ui/window/JDialogAttribute.java b/src/main/java/ui/window/JDialogAttribute.java index 1a10c1144c..82e1261187 100644 --- a/src/main/java/ui/window/JDialogAttribute.java +++ b/src/main/java/ui/window/JDialogAttribute.java @@ -57,7 +57,7 @@ import java.util.LinkedList; * Class JDialogAttribute * Dialog for managing attributes * Creation: 18/12/2003 - * @version 1.0 18/12/2003 + * @version 2.0 04/03/2019 * @author Ludovic APVRILLE */ public class JDialogAttribute extends JDialogBase implements ActionListener, ListSelectionListener { @@ -70,6 +70,11 @@ public class JDialogAttribute extends JDialogBase implements ActionListener, Lis protected Frame frame; protected String attrib; // "Attributes", "Gates", etc. + + // Operation type + protected String operation; + protected JPanel panelOperation; + protected JTextField operationField; // Panel1 protected JComboBox<String> accessBox, typeBox; @@ -84,13 +89,15 @@ public class JDialogAttribute extends JDialogBase implements ActionListener, Lis protected JButton removeButton; /* Creates new form */ - public JDialogAttribute(java.util.List<TAttribute> _attributes, java.util.List<TAttribute>_forbidden, Frame f, String title, String attrib) { + public JDialogAttribute(java.util.List<TAttribute> _attributes, java.util.List<TAttribute>_forbidden, Frame f, + String title, String attrib, String _operation) { super(f, title, true); frame = f; attributesPar = _attributes; forbidden = _forbidden; initValues = new LinkedList<Boolean> (); this.attrib = attrib; + this.operation = _operation; attributes = new LinkedList<TAttribute> (); @@ -233,6 +240,31 @@ public class JDialogAttribute extends JDialogBase implements ActionListener, Lis removeButton = new JButton("Remove " + attrib); removeButton.addActionListener(this); panel2.add(removeButton, c2); + + // Operation panel + if (operation != null) { + GridBagLayout gbOp = new GridBagLayout(); + GridBagConstraints cOp = new GridBagConstraints(); + panelOperation = new JPanel(); + panelOperation.setLayout(gbOp); + panelOperation.setBorder(new javax.swing.border.TitledBorder("Operation type (empty means unspecified)")); + //panelOperation.setPreferredSize(new Dimension(500, 70)); + + cOp.weighty = 1.0; + cOp.weightx = 1.0; + cOp.gridwidth = GridBagConstraints.REMAINDER; //end row + cOp.fill = GridBagConstraints.BOTH; + cOp.gridheight = 3; + operationField = new JTextField(operation); + panelOperation.add(operationField, cOp); + + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.fill = GridBagConstraints.BOTH; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + c.add(panelOperation, c0); + + } // main panel; c0.gridwidth = 1; @@ -240,7 +272,9 @@ public class JDialogAttribute extends JDialogBase implements ActionListener, Lis c0.weighty = 1.0; c0.weightx = 1.0; c0.fill = GridBagConstraints.BOTH; - + + + c.add(panel1, c0); c0.gridwidth = GridBagConstraints.REMAINDER; //end row c.add(panel2, c0); @@ -472,5 +506,12 @@ public class JDialogAttribute extends JDialogBase implements ActionListener, Lis } } } + + public String getOperation() { + if (operationField != null) { + return operationField.getText().trim(); + } + return ""; + } } -- GitLab