-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="&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 &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="&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 &PNML"> | ||
</command> | ||
<command | ||
defaultHandler="es.unizar.disco.pnml.utils.handlers.ValidatePnml" | ||
id="es.unizar.disco.pnml.utils.popup.handlers.ValidatePnml" | ||
name="Validate &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> |
61 changes: 61 additions & 0 deletions
61
es.unizar.disco.pnml.utils/src/es/unizar/disco/pnml/utils/handlers/ValidatePnml.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |