Commit 100233ef authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ added command to reload constraints (for development mostly), &36

parent 19a97b6e
Loading
Loading
Loading
Loading
+869 B
Loading image diff...
+27 −1
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@
            categoryId="org.etsi.mts.tdl.tools.rt.ui.commands.category"
            id="org.etsi.mts.tdl.tools.rt.ui.commands.tp2tdCommand">
      </command>
      <command
            name="Reload OCL constraints"
            categoryId="org.etsi.mts.tdl.tools.rt.ui.commands.category"
            id="org.etsi.mts.tdl.tools.rt.ui.commands.reloadValidatorCommand">
      </command>
   </extension>
   <extension
         point="org.eclipse.ui.handlers">
@@ -29,6 +34,10 @@
            commandId="org.etsi.mts.tdl.tools.rt.ui.commands.tp2tdCommand"
            class="org.etsi.mts.tdl.tools.rt.ui.handlers.TP2TDHandler">
      </handler>
      <handler
            commandId="org.etsi.mts.tdl.tools.rt.ui.commands.reloadValidatorCommand"
            class="org.etsi.mts.tdl.tools.rt.ui.handlers.ReloadValidationHandler">
      </handler>
   </extension>
   <extension
         point="org.eclipse.ui.bindings">
@@ -61,10 +70,21 @@
            <command
                  commandId="org.etsi.mts.tdl.tools.rt.ui.commands.tp2tdCommand"
                  icon="icons/TransformIcon.png"
                  mnemonic="T"
                  mnemonic="P"
                  id="org.etsi.mts.tdl.tools.rt.ui.menus.tp2tdCommand">
            </command>
         </menu>
         <menu
               label="TDL"
               mnemonic="T"
               id="org.etsi.mts.tdl.tools.menus.TDLMenu">
            <command
                  commandId="org.etsi.mts.tdl.tools.rt.ui.commands.reloadValidatorCommand"
                  icon="icons/ValidateIcon.png"
                  mnemonic="V"
                  id="org.etsi.mts.tdl.tools.rt.ui.menus.reloadValidatorCommand">
            </command>
         </menu>
      </menuContribution>
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
@@ -82,6 +102,12 @@
                  tooltip="Transform TPs to TDs"
                  id="org.etsi.mts.tdl.tools.rt.ui.toolbars.tp2tdCommand">
            </command>
            <command
                  commandId="org.etsi.mts.tdl.tools.rt.ui.commands.reloadValidatorCommand"
                  icon="icons/ValidateIcon.png"
                  tooltip="Reload OCL constraints"
                  id="org.etsi.mts.tdl.tools.rt.ui.toolbars.reloadValidatorCommand">
            </command>
         </toolbar>
      </menuContribution>
   </extension>
+58 −0
Original line number Diff line number Diff line
package org.etsi.mts.tdl.tools.rt.ui.handlers;

import java.util.LinkedHashMap;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.ui.IWorkbenchWindow;
import org.etsi.mts.tdl.Validator;
import org.etsi.mts.tdl.tdlPackage;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

/**
 * Our sample handler extends AbstractHandler, an IHandler base class.
 * @see org.eclipse.core.commands.IHandler
 * @see org.eclipse.core.commands.AbstractHandler
 */
public class ReloadValidationHandler extends AbstractHandler {
	LinkedHashMap<String, String> targetFormats = new LinkedHashMap<>();

	private IWorkbenchWindow window;

	/**
	 * The constructor.
	 */
	public ReloadValidationHandler() {
		init();
	}

	private void init() {
	}


	/**
	 * the command has been executed, so extract extract the needed information
	 * from the application context.
	 */
	public Object execute(ExecutionEvent event) throws ExecutionException {
		EValidator.Registry.INSTANCE.remove(tdlPackage.eINSTANCE);
		Bundle bundle = Platform.getBundle("org.etsi.mts.tdl.model");
		BundleContext context = bundle.getBundleContext();
		Validator.registerValidator("model/tdl-constraints.ocl", tdlPackage.eINSTANCE, context);
		return null;
	}
		
	public void init(IWorkbenchWindow window) {
		this.window = window;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}