Skip to content

Commit

Permalink
[#360] Bitwalker DataDictionary to SysML transformation implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfronc committed Oct 10, 2014
1 parent 276e06e commit 24d7358
Show file tree
Hide file tree
Showing 13 changed files with 1,440 additions and 578 deletions.
Expand Up @@ -10,6 +10,7 @@
public class Activator extends AbstractUIPlugin {

// The plug-in ID
@SuppressWarnings("javadoc")
public static final String PLUGIN_ID = "org.openetcs.datadictionary.transform.ui"; //$NON-NLS-1$

// The shared instance
Expand Down
@@ -0,0 +1,181 @@
package org.openetcs.datadictionary.transform.ui;

import java.io.File;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
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.Control;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

/**
* Configuration dialog for Bitwalker transform.
*
*/
public class TransformationDialog extends TitleAreaDialog {

static String[] FILE_EXTENSIONS = { "*.xml" };
static String[] FILE_NAMES = { "Bitwalker xml" };

private String[] mFiles;
private String mModelName;
private String mProjectName;
private ListViewer mListViewer;
private Text mTxtModelName;
private Text mTxtProjectName;

/**
* Create the dialog
*
* @param parentShell shell to be used.
*/
public TransformationDialog(final Shell parentShell) {
super(parentShell);
}

@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout(1, false);
composite.setLayout(layout);

mListViewer = new ListViewer(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
List list = mListViewer.getList();
GridData gd_list = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
gd_list.heightHint = 80;
list.setLayoutData(gd_list);

Composite composite_1 = new Composite(composite, SWT.NONE);
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
composite_1.setLayout(new GridLayout(4, false));

Label lblNewLabel = new Label(composite_1, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("Project name");

mTxtProjectName = new Text(composite_1, SWT.BORDER);
mTxtProjectName.setText("DataDictionary");
mTxtProjectName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

Button btnRemove = new Button(composite_1, SWT.NONE);
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) mListViewer.getSelection();
if (selection.size() > 0) {
for (Object file : selection.toArray()) {
mListViewer.remove((String)file);
}
}
}
});
btnRemove.setBounds(0, 0, 69, 25);
btnRemove.setText("Remove");

Button btnAdd = new Button(composite_1, SWT.NONE);
btnAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
dialog.setFilterExtensions(FILE_EXTENSIONS);
dialog.setFilterNames(FILE_NAMES);

if (dialog.open() != null) {
StringBuffer buf = new StringBuffer();
String[] files = dialog.getFileNames();
String filter = dialog.getFilterPath();
for (String file : files) {
buf.append(filter);
if (buf.charAt(buf.length() - 1) != File.separatorChar) {
buf.append(File.separatorChar);
}
buf.append(file);
mListViewer.remove(buf.toString());
mListViewer.add(buf.toString());
buf.setLength(0);
}
}
}
});
btnAdd.setBounds(0, 0, 69, 25);
btnAdd.setText("Add");

Label lblModelName = new Label(composite_1, SWT.NONE);
lblModelName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblModelName.setText("Model name");

mTxtModelName = new Text(composite_1, SWT.BORDER);
mTxtModelName.setText("DataDictionary");
mTxtModelName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

mModelName = mTxtModelName.getText();
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);
return composite;
}


/**
* Get Bitwalker files (available after widget is disposed).
*
* @return get Bitwalker files.
*/
public String[] getFiles() {
return mFiles;
}

/**
* Get model name (available after widget is disposed).
*
* @return model name.
*/
public String getModelName() {
return mModelName;
}

/**
* Get project name (available after widget is disposed).
*
* @return project name.
*/
public String getProjectName() {
return mProjectName;
}

@Override
public void create() {
super.create();
setTitle("Generate the DataDictionary model.");
setMessage("Select bitwalker files to transform.");
}

@Override
protected Point getInitialLocation(Point initialSize) {
Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Rectangle shellBounds = parentShell.getBounds();
Point shellCenter = new Point(shellBounds.x + shellBounds.width / 2, (shellBounds.y + shellBounds.height) / 2);
return new Point(shellCenter.x - initialSize.x / 2, shellCenter.y - initialSize.y / 2);
}

@Override
protected void okPressed() {
mFiles = mListViewer.getList().getItems();
mModelName = mTxtModelName.getText();
mProjectName = mTxtProjectName.getText();
super.okPressed();
}
}
@@ -1,23 +1,20 @@
package org.openetcs.datadictionary.transform.ui.handlers;

import java.io.File;
import java.util.Arrays;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.ide.IDE;
import org.openetcs.datadictionary.transform.ITransformService;
import org.openetcs.datadictionary.transform.ITransformer;
import org.openetcs.datadictionary.transform.TransformServiceFactory;
import org.openetcs.datadictionary.transform.ui.TransformationDialog;


/**
* Our sample handler extends AbstractHandler, an IHandler base class.
Expand All @@ -43,43 +40,26 @@ public TransformHandler() {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

ITransformService transformer = TransformServiceFactory.getInstance();

// open file dialog
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event)
.getShell();

FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterExtensions(FILE_EXTENSIONS);
dialog.setFilterNames(FILE_NAMES);
String file = dialog.open();

if (file != null) {
String output = transformer.transform(file);

if (output == null) {
MessageDialog error_dialog = new MessageDialog(shell,
"Transformation Error", null,
"Unable to perform transformation",
MessageDialog.ERROR, new String[] { "Continue" }, 0);
error_dialog.open();
return null;
}

File f = new File(output);
IFileStore store = EFS.getLocalFileSystem().getStore(f.toURI());
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditorOnFileStore(page, store);
} catch (PartInitException e) {
MessageDialog error_dialog = new MessageDialog(shell,
"Transformation Error", null, "Could not open editor",
MessageDialog.ERROR, new String[] { "Continue" }, 0);
error_dialog.open();
}
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
final TransformationDialog dialog = new TransformationDialog(shell);
dialog.open();
final String[] files = dialog.getFiles();

if (files != null && files.length > 0) {
Job job = new Job("Generating DataDictionary") {
protected IStatus run(IProgressMonitor monitor) {
Arrays.sort(files);
ITransformer transformer = TransformServiceFactory.createTransformer();
boolean res = transformer.transform(dialog.getProjectName(), dialog.getModelName(), files, monitor, ITransformer.LOG_WARN);
return res ? Status.OK_STATUS : Status.CANCEL_STATUS;
}
};
job.setPriority(Job.SHORT);
job.schedule();

}

return null;
}
}
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.xtend.XTEND_CONTAINER"/>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
Expand Down
Expand Up @@ -14,7 +14,11 @@ Require-Bundle: org.eclipse.ui,
com.google.guava,
org.eclipse.xtext.xbase.lib,
org.eclipse.uml2.uml,
org.eclipse.papyrus.sysml
org.eclipse.papyrus.sysml,
org.eclipse.papyrus.infra.core,
org.eclipse.papyrus.infra.gmfdiag.common,
org.eclipse.papyrus.sysml.diagram.common,
org.eclipse.papyrus.uml.tools.utils
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: Subset0267,
Subset0267.impl,
Expand Down
Expand Up @@ -7,4 +7,13 @@ bin.includes = plugin.xml,\
models/Subset_026_7.xml,\
models/Subset_026_8.xml
additional.bundles = org.eclipse.xtend.lib,\
org.eclipse.papyrus.sysml
org.eclipse.papyrus.sysml,\
org.eclipse.gmf.runtime.emf.core,\
org.eclipse.papyrus.infra.core,\
org.eclipse.papyrus.infra.gmfdiag.common,\
org.eclipse.papyrus.infra.core.sasheditor,\
org.eclipse.papyrus.sysml.diagram.common,\
org.eclipse.papyrus.sysml.diagram.blockdefinition,\
org.eclipse.gmf.runtime.diagram.ui,\
org.eclipse.gmf.runtime.common.ui,\
org.eclipse.papyrus.uml.tools.utils
Expand Up @@ -10,6 +10,7 @@
public class Activator extends AbstractUIPlugin {

// The plug-in ID
@SuppressWarnings("javadoc")
public static final String PLUGIN_ID = "org.openetcs.datadictionary.transform"; //$NON-NLS-1$

// The shared instance
Expand Down

0 comments on commit 24d7358

Please sign in to comment.