Skip to content

Commit

Permalink
Add rudimentary validation support
Browse files Browse the repository at this point in the history
  • Loading branch information
abelgomez committed Nov 6, 2015
1 parent 683dd8f commit f848bac
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 53 deletions.
4 changes: 2 additions & 2 deletions es.unizar.disco.pnml.utils.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="es.unizar.disco.pnml.utils.feature"
label="PNML Utils"
version="0.1.1.qualifier"
version="0.1.2.qualifier"
provider-name="DisCo - Unizar">

<description url="https://github.com/dice-project/DICE-Simulation-Utils">
Expand Down Expand Up @@ -237,7 +237,7 @@ any resulting litigation.
id="es.unizar.disco.pnml.utils"
download-size="0"
install-size="0"
version="0.1.1.qualifier"
version="0.1.2.qualifier"
unpack="false"/>

</feature>
2 changes: 1 addition & 1 deletion es.unizar.disco.pnml.utils/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: PNML Utils
Bundle-SymbolicName: es.unizar.disco.pnml.utils;singleton:=true
Bundle-Version: 0.1.1.qualifier
Bundle-Version: 0.1.2.qualifier
Bundle-Activator: es.unizar.disco.pnml.utils.PnmlUtilsPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand Down
122 changes: 72 additions & 50 deletions es.unizar.disco.pnml.utils/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,50 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<menu
label="&amp;PNML Utils">
<command
commandId="es.unizar.disco.pnml.utils.popup.handlers.ConvertToPnml"
style="push"
tooltip="Converts a PNML file stored as an XMI into its correspondent XML representation">
<visibleWhen
checkEnabled="false">
<iterate>
<and>
<test
forcePluginActivation="true"
property="es.unizar.disco.pnml.utils.isPnmlXmi"
value="true">
</test>
</and>
</iterate>
</visibleWhen>
</command>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="es.unizar.disco.pnml.utils.handlers.ConvertToPnml"
id="es.unizar.disco.pnml.utils.popup.handlers.ConvertToPnml"
name="Convert to &amp;PNML">
</command>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="es.unizar.disco.pnml.utils.testers.PnmlXmiPropertyTester"
id="es.unizar.disco.pnml.utils.isPnmlXmi"
namespace="es.unizar.disco.pnml.utils"
properties="isPnmlXmi"
type="org.eclipse.core.resources.IFile">
</propertyTester>
</extension>

</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<menu
label="&amp;PNML Utils">
<command
commandId="es.unizar.disco.pnml.utils.popup.handlers.ConvertToPnml"
style="push"
tooltip="Converts a PNML file stored as an XMI into its correspondent XML representation">
<visibleWhen
checkEnabled="false">
<iterate>
<and>
<test
forcePluginActivation="true"
property="es.unizar.disco.pnml.utils.isPnmlXmi"
value="true">
</test>
</and>
</iterate>
</visibleWhen>
</command>
<command
commandId="es.unizar.disco.pnml.utils.popup.handlers.ValidatePnml"
style="push"
tooltip="Validates a PNML file">
<visibleWhen
checkEnabled="false">
<iterate>
<and>
<test
forcePluginActivation="true"
property="org.eclipse.core.resources.extension"
value="pnml">
</test>
</and>
</iterate>
</visibleWhen>
</command>
</menu>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="es.unizar.disco.pnml.utils.handlers.ConvertToPnml"
id="es.unizar.disco.pnml.utils.popup.handlers.ConvertToPnml"
name="Convert to &amp;PNML">
</command>
<command
defaultHandler="es.unizar.disco.pnml.utils.handlers.ValidatePnml"
id="es.unizar.disco.pnml.utils.popup.handlers.ValidatePnml"
name="Validate &amp;PNML">
</command>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="es.unizar.disco.pnml.utils.testers.PnmlXmiPropertyTester"
id="es.unizar.disco.pnml.utils.isPnmlXmi"
namespace="es.unizar.disco.pnml.utils"
properties="isPnmlXmi"
type="org.eclipse.core.resources.IFile">
</propertyTester>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package es.unizar.disco.pnml.utils.handlers;

import java.util.Iterator;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import es.unizar.disco.pnml.utils.PnmlUtilsPlugin;
import fr.lip6.move.pnml.framework.utils.PNMLUtils;
import fr.lip6.move.pnml.framework.utils.exception.ImportException;
import fr.lip6.move.pnml.framework.utils.exception.InvalidIDException;

public class ValidatePnml extends AbstractHandler {

public static final String ID = "es.unizar.disco.pnml.utils.popup.handlers.ConvertToPnml";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
if (selection != null & selection instanceof IStructuredSelection) {
final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Job job = new Job(ID) {
@Override
protected IStatus run(IProgressMonitor monitor) {
if (monitor == null) monitor = new NullProgressMonitor();
try {
monitor.beginTask("Validating PNML", IProgressMonitor.UNKNOWN);
for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
// TODO: Handle selection on multiple files for the return status (i.e. use MultiStatus when needed)
Object obj = iterator.next();
if (obj instanceof IFile) {
IFile file = (IFile) obj;
try {
PNMLUtils.importPnmlDocument(file.getLocation().toFile(), false);
} catch (InvalidIDException | ImportException e) {
return new Status(IStatus.ERROR, PnmlUtilsPlugin.PLUGIN_ID, e.getLocalizedMessage(), e);
}
}
}
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();

}
return null;
}
}

0 comments on commit f848bac

Please sign in to comment.