Adds OPTIMUS plugin

parent 21770256
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="bin/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="D:/W/2017-Decide/workspace/json-simple-1.1.1.jar">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="../"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="bin"/>
</classpath>
bin/
.settings/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>eu.DECIDEh2020.optimus</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<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.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Optimus
Bundle-SymbolicName: eu.DECIDEh2020.optimus;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.jface.text,
org.eclipse.core.resources,
org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.ui.ide,
org.eclipse.core.runtime,
com.googlecode.json-simple;bundle-version="1.1.1",
org.eclipse.json;bundle-version="1.0.100"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: bin/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
icons/,\
bin/
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.editors">
<editor
name="Optimus Editor"
extensions="json"
filenames="*.json"
icon="icons/decide.png"
contributorClass="eu.DECIDEh2020.optimus.editors.OptimusContributor"
class="eu.DECIDEh2020.optimus.editors.optimus"
id="eu.DECIDEh2020.optimus.editors.optimus">
</editor>
</extension>
<extension
point="org.eclipse.ui.newWizards">
<category
name="Optimus Wizards"
id="eu.DECIDEh2020.optimus">
</category>
<wizard
name="Optimus Editor file"
icon="icons/decide.png"
category="eu.DECIDEh2020.optimus"
class="eu.DECIDEh2020.optimus.wizards.OptimusWizard"
id="eu.DECIDEh2020.optimus.wizards.OptimusWizard">
</wizard>
</extension>
</plugin>
/*********************************************************************
* Copyright (c) 2017 Tecnalia.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* Contributors (in alphabetical order):
* Gorka Benguria Tecnalia
* Iaki Etxaniz Tecnalia
* Juncal Alonso Tecnalia
* Leire Orue-Echevarria Tecnalia
* Maria Jose Lopez Tecnalia
* Marisa Escalante Tecnalia
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
**********************************************************************/
package eu.DECIDEh2020.optimus.editors;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.json.simple.JSONArray;
//import org.json.simple.JSONException;
import org.json.simple.JSONObject;
import java.awt.Rectangle;
//import org.json.parser.JSONParser;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class Classification extends Composite {
/**
* Create the composite.
* @param parent
* @param style
*/
/** The text widget used in page 2. */
private StyledText text;
/** The font chosen in page 1. */
private Font font;
private Text text_1;
private Composite text_2;
public int microservicesNumber = 0;
public int y = 5;
public String newcontent;
public Classification(Composite parent, int style) {
super(parent, style);
Label lblAppName = new Label(this, SWT.NONE);
lblAppName.setBounds(10, 10, 55, 15);
lblAppName.setText("App name");
text_1 = new Text(this, SWT.BORDER);
text_1.setBounds(74, 10, 76, 21);
text_1.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void focusLost(FocusEvent arg0) {
newcontent = text_1.getText();
optimus.appjson.put("id", (int) (Math.random()*1000));
optimus.appjson.put("name", newcontent);
}});
Button btnAddMicroservice = new Button(this, SWT.NONE);
btnAddMicroservice.setBounds(181, 10, 130, 25);
btnAddMicroservice.setText("Add microservice");
ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
scrolledComposite.setExpandHorizontal(true);
scrolledComposite.setTouchEnabled(true);
scrolledComposite.setShowFocusedControl(true);
scrolledComposite.setAlwaysShowScrollBars(true);
scrolledComposite.setBounds(10, 48, 753, 596);
scrolledComposite.setMinHeight(y);
final StyledText styledText = new StyledText(scrolledComposite, SWT.BORDER | SWT.WRAP);
scrolledComposite.setContent(styledText);
scrolledComposite.setMinSize(styledText.computeSize(SWT.DEFAULT, SWT.DEFAULT));
Button btnSave = new Button(this, SWT.NONE);
btnSave.setBounds(688, 660, 75, 25);
btnSave.setText("Save");
btnSave.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
optimus.appjson.put("microservices", optimus.appmicros);
final String FILENAME = optimus.workingDir;
BufferedWriter bw = null;
FileWriter fw = null;
try {
String content = optimus.appjson.toString();
fw = new FileWriter(FILENAME);
bw = new BufferedWriter(fw);
bw.write(content);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bw != null)
bw.close();
if (fw != null)
fw.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
});
btnAddMicroservice.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
microservicesNumber = microservicesNumber + 1;
//scrolledComposite.setMinHeight(y);
text_2 = new Microservice(scrolledComposite, SWT.BORDER, y);
text_2.setBounds(10, y, 500, 100);
y = (120* microservicesNumber);
}
});
}
public void Create_microservices_from_file() {
if (!(optimus.appjson.isEmpty()))
{
text_1.setText(optimus.appjson.get("name").toString());
ScrolledComposite scrolledComposite = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
scrolledComposite.setTouchEnabled(true);
scrolledComposite.setShowFocusedControl(true);
scrolledComposite.setAlwaysShowScrollBars(true);
scrolledComposite.setExpandVertical(true);
scrolledComposite.setBounds(10, 48, 753, 427);
optimus.appjson.get("name").toString();
optimus.appmicros.remove("microservices");
optimus.appmicros.add(optimus.appjson.get("microservices"));
int numbermicr=optimus.appmicros.size();
for (int i = 0; i <numbermicr; i++)
{
microservicesNumber = microservicesNumber + 1;
text_2 = new Microservice(scrolledComposite, SWT.BORDER, y);
text_2.setBounds(10, y, 500, 100);
y = (120* microservicesNumber);
// }
}
}
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
/*********************************************************************
* Copyright (c) 2017 Tecnalia.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* Contributors (in alphabetical order):
* Gorka Benguria Tecnalia
* Iaki Etxaniz Tecnalia
* Juncal Alonso Tecnalia
* Leire Orue-Echevarria Tecnalia
* Maria Jose Lopez Tecnalia
* Marisa Escalante Tecnalia
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
**********************************************************************/
package eu.DECIDEh2020.optimus.editors;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.FillLayout;
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.FontDialog;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.eclipse.swt.widgets.Combo;
public class Microservice extends Composite {
/**
* Create the composite.
* @param parent
* @param style
*/
/** The text widget used in page 2. */
private StyledText text;
/** The font chosen in page 1. */
private Font font;
private Text text_1;
private Text text_2;
private static JSONObject micros;
private JSONArray DetachR;
private Text Detach_text;
private JSONObject DRes;
public Microservice(Composite parent, int style, int y) {
super(parent, style);
Composite compositeMicro = new Composite(this, SWT.NONE);
compositeMicro.setBounds(1, 0, 437, 83);
DetachR = new JSONArray();
Label lblMicroserviceName = new Label(compositeMicro, SWT.NONE);
lblMicroserviceName.setBounds(10, 13, 50, 30);
lblMicroserviceName.setText("Name");
text_2 = new Text(compositeMicro, SWT.BORDER);
text_2.setBounds(69, 13, 200, 21);
Label microserviceID = new Label(compositeMicro, SWT.NONE);
microserviceID.setText("id");
microserviceID.setBounds(275, 13, 50, 15);
microserviceID.setVisible(false);
Combo ms_type = new Combo(compositeMicro, SWT.NONE);
ms_type.setItems(new String[] {"Computing", "Computing Public IP"});
ms_type.setBounds(331, 10, 91, 23);
ms_type.setText("Computing");
Combo Detach_type = new Combo(compositeMicro, SWT.NONE);
Detach_type.setItems(new String[] {"Storage. DB", "Storage", "Queue System"});
Detach_type.setBounds(322, 50, 91, 23);
Detach_type.setText("Storage");
Button Det_DB = new Button(compositeMicro, SWT.RADIO);
Det_DB.setSelection(false);
Det_DB.setBounds(277, 53, 90, 16);
Det_DB.setText("DB");
Det_DB.addFocusListener(new FocusListener(){
@Override
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void focusLost(FocusEvent arg0) {
if (Det_DB.getSelection()) {
Detach_type.setText("Storage. DB");
}
if (!Det_DB.getSelection()) {Detach_type.setText("Storage");}
if (DRes.get(Detach_type)!=Detach_type.getText())
{
DetachR.remove(DRes);
micros.remove(DetachR);
optimus.appmicros.remove(micros);
DRes.put("Det_type",Detach_type.getText());
DetachR.add(DRes);
optimus.appmicros.add(micros);
}
}
}
);
Label lblDetachableResource = new Label(compositeMicro, SWT.NONE);
lblDetachableResource.setBounds(11, 53, 122, 15);
lblDetachableResource.setText("Detachable Resource");
Detach_text = new Text(compositeMicro, SWT.BORDER);
Detach_text.setBounds(143, 47, 117, 21);
Detach_text.addFocusListener(new FocusListener(){
@Override
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void focusLost(FocusEvent arg0) {
DRes = new JSONObject();
for (int i=0; i < optimus.appmicros.size(); i++)
{
JSONObject itemArr = (JSONObject)optimus.appmicros.get(i);
if (itemArr.get("id").equals(microserviceID.getText()))
{
break;
}
}
DRes.put("DetachableResource",Detach_text.getText());
DRes.put("Det_type",Detach_type.getText());
DetachR.add(DRes);
micros.put("Detachable_resources",DetachR);
}
});
text_2.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void focusLost(FocusEvent arg0) {
int id = (int) (Math.random()*1000);
String idS = String.valueOf(id);
micros = new JSONObject();
for (int i=0; i < optimus.appmicros.size(); i++)
{
JSONObject itemArr = (JSONObject)optimus.appmicros.get(i);
if (itemArr.get("id").equals(microserviceID.getText()))
{
optimus.appmicros.remove(itemArr);
idS = microserviceID.getText();
break;
}
}
micros.put("id",idS);
micros.put("microname", text_2.getText());
micros.put("ms_type", ms_type.getText());
optimus.appmicros.add(micros);
microserviceID.setText(idS);
microserviceID.setVisible(true);
}
private boolean existmicroservice(String text) {
JSONObject microstemp = new JSONObject();
microstemp.put("id",text);
microstemp.put("microname", text_2.getText());
if (optimus.appmicros.contains(microstemp)) {
return true;
} else {
return false;
}
}});
}
//});
//}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
/*********************************************************************
* Copyright (c) 2017 Tecnalia.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* Contributors (in alphabetical order):
* Gorka Benguria Tecnalia
* Iaki Etxaniz Tecnalia
* Juncal Alonso Tecnalia
* Leire Orue-Echevarria Tecnalia
* Maria Jose Lopez Tecnalia
* Marisa Escalante Tecnalia
* Initially developed in the context of DECIDE EU project www.DECIDE-h2020.eu
**********************************************************************/
package eu.DECIDEh2020.optimus.editors;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
/**
* Manages the installation/deinstallation of global actions for multi-page editors.
* Responsible for the redirection of global actions to the active editor.
* Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
*/
public class OptimusContributor extends MultiPageEditorActionBarContributor {
private IEditorPart activeEditorPart;
private Action sampleAction;
/**
* Creates a multi-page contributor.
*/
public OptimusContributor() {
super();
createActions();
}
/**
* Returns the action registed with the given text editor.
* @return IAction or null if editor is null.
*/
protected IAction getAction(ITextEditor editor, String actionID) {
return (editor == null ? null : editor.getAction(actionID));
}
/* (non-JavaDoc)
* Method declared in AbstractMultiPageEditorActionBarContributor.
*/
public void setActivePage(IEditorPart part) {
if (activeEditorPart == part)
return;
activeEditorPart = part;
IActionBars actionBars = getActionBars();
if (actionBars != null) {
ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;
actionBars.setGlobalActionHandler(
ActionFactory.DELETE.getId(),
getAction(editor, ITextEditorActionConstants.DELETE));
actionBars.setGlobalActionHandler(
ActionFactory.UNDO.getId(),
getAction(editor, ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(
ActionFactory.REDO.getId(),
getAction(editor, ITextEditorActionConstants.REDO));
actionBars.setGlobalActionHandler(
ActionFactory.CUT.getId(),
getAction(editor, ITextEditorActionConstants.CUT));
actionBars.setGlobalActionHandler(
ActionFactory.COPY.getId(),
getAction(editor, ITextEditorActionConstants.COPY));
actionBars.setGlobalActionHandler(
ActionFactory.PASTE.getId(),
getAction(editor, ITextEditorActionConstants.PASTE));
actionBars.setGlobalActionHandler(
ActionFactory.SELECT_ALL.getId(),
getAction(editor, ITextEditorActionConstants.SELECT_ALL));
actionBars.setGlobalActionHandler(
ActionFactory.FIND.getId(),
getAction(editor, ITextEditorActionConstants.FIND));
actionBars.setGlobalActionHandler(
IDEActionFactory.BOOKMARK.getId(),
getAction(editor, IDEActionFactory.BOOKMARK.getId()));
actionBars.updateActionBars();
}
}
private void createActions() {
sampleAction = new Action() {
public void run() {
MessageDialog.openInformation(null, "Optimus", "Sample Action Executed");
}
};
sampleAction.setText("Sample Action");
sampleAction.setToolTipText("Sample Action tool tip");
sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK));
}
public void contributeToMenu(IMenuManager manager) {
IMenuManager menu = new MenuManager("Editor &Menu");
manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu);
menu.add(sampleAction);
}
public void contributeToToolBar(IToolBarManager manager) {
manager.add(new Separator());
manager.add(sampleAction);
}
}
/*********************************************************************
* Copyright (c) 2017 Tecnalia.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* Contributors (in alphabetical order):
* Gorka Benguria Tecnalia
* Iaki Etxaniz Tecnalia
* Juncal Alonso Tecnalia