001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: //
009: //
010:
011: /* Generated by Together */
012:
013: package de.uka.ilkd.key.casetool.together.scripts.menuextension;
014:
015: import com.togethersoft.openapi.ide.IdeContext;
016: import com.togethersoft.openapi.ide.command.IdeCommandAdapter;
017: import com.togethersoft.openapi.ide.command.IdeCommandEvent;
018: import com.togethersoft.openapi.ide.diagram.IdeDiagramManagerAccess;
019: import com.togethersoft.openapi.ide.window.IdeWindowManager;
020: import com.togethersoft.openapi.rwi.RwiDiagram;
021: import com.togethersoft.openapi.rwi.RwiModel;
022: import com.togethersoft.openapi.rwi.RwiModelAccess;
023:
024: import de.uka.ilkd.key.casetool.together.keydebugclassloader.KeyDebugClassLoader;
025:
026: public class ClassMenuIdeAdapter extends IdeCommandAdapter {
027:
028: public ClassMenuIdeAdapter(KeyMenuExtension script,
029: IdeWindowManager aWinMan, int ind1, String className) {
030: lnkKeyMenuExtension = script;
031: winMan = aWinMan;
032: groupElementNo = ind1;
033: classMenuRootCN = className;
034: }
035:
036: private int groupElementNo;
037: private String classMenuRootCN;
038: private IdeWindowManager winMan;
039: private KeyMenuExtension lnkKeyMenuExtension;
040:
041: public void checkStatus(IdeCommandEvent event) {
042: try {
043: lnkKeyMenuExtension.myClassItem[groupElementNo - 1]
044: .setText(((ClassMenu) Class.forName(
045: classMenuRootCN + "Point" + groupElementNo)
046: .newInstance()).getMenuEntry());
047: } catch (ExceptionInInitializerError ei) {
048: System.err
049: .println("classmenuideadapter: the initialization provoked "
050: + "by this method fails.");
051: System.err.println("The exception was: " + ei);
052: ei.printStackTrace();
053: } catch (ClassNotFoundException cnfe) {
054: System.err
055: .println("classmenuideadapter: class cannot be located");
056: System.err.println("The exception was: " + cnfe);
057: cnfe.printStackTrace();
058: } catch (IllegalAccessException iae) {
059: System.err.println("classmenuideadapter: class or "
060: + "initializer is not accessible.");
061: System.err.println("The exception was: " + iae);
062: iae.printStackTrace();
063: } catch (InstantiationException ie) {
064: System.err
065: .println("classmenuideadapter: class tried to\n"
066: + "instantiate represents an abstract class, an interface,"
067: + "an array class, a primitive type, or void; or if the"
068: + "instantiation fails for some other reason.");
069: System.err.println("The exception was: " + ie);
070: ie.printStackTrace();
071: } catch (SecurityException se) {
072: System.err
073: .println("classmenuideadapter: no permission to create"
074: + "a new instance");
075: System.err.println("The exception was: " + se);
076: se.printStackTrace();
077: } catch (LinkageError le) {
078: System.err.println("classmenuideadapter: linkage failed");
079: System.err.println("The exception was: " + le);
080: le.printStackTrace();
081: }
082:
083: lnkKeyMenuExtension.myClassItem[groupElementNo - 1]
084: .setEnabled(true);
085: lnkKeyMenuExtension.myClassItem[groupElementNo - 1]
086: .setVisible(true);
087: }
088:
089: public void actionPerformed(IdeCommandEvent event) {
090: // what should be done be selecting this context menu
091: IdeContext context = event.getElementContext(); //getting the element(s) under the cursor
092: RwiDiagram activeRwiDiagram = IdeDiagramManagerAccess
093: .getDiagramManager().getActiveDiagram().getRwiDiagram();
094: RwiModel currentRwiModel = RwiModelAccess.getModel();
095:
096: Class cl;
097: ClassLoader classLoader = this .getClass().getClassLoader();
098: if ("on".equals(System.getProperty("KeyDebugClassLoader"))) {
099: // installing the keydebugclassloader instead
100: // see also de.uka.ilkd.tjext.keydebugclassloader.KeyScript
101: try {
102: classLoader = new KeyDebugClassLoader(classLoader);
103: ((KeyDebugClassLoader) classLoader)
104: .setClassAlwaysAskParent(ClassMenu.class);
105: } catch (SecurityException se) {
106: System.err
107: .println("classmenuideadapter: security manager exists and\n"
108: + "its checkPermission method doesn't allow access\n"
109: + "to the system class loader.");
110: System.err.println("KeYError: " + se);
111: se.printStackTrace();
112: }
113: }
114: try {
115: cl = classLoader.loadClass(classMenuRootCN + "Point"
116: + groupElementNo);
117: // now creating an instance of the (re)loaded class and
118: // invoking the run-method
119: ClassMenu instance = (ClassMenu) cl.newInstance();
120: instance.run(winMan, context, currentRwiModel,
121: activeRwiDiagram);
122: } catch (ClassNotFoundException cnfe) {
123: System.err
124: .println("classmenuideadapter: class cannot be located");
125: System.err.println("The exception was: " + cnfe);
126: cnfe.printStackTrace();
127: } catch (ExceptionInInitializerError ei) {
128: System.err
129: .println("classmenuideadapter: the initialization provoked "
130: + "by this method fails.");
131: System.err.println("The exception was: " + ei);
132: ei.printStackTrace();
133: } catch (IllegalAccessException iae) {
134: System.err.println("classmenuideadapter: class or "
135: + "initializer is not accessible.");
136: System.err.println("The exception was: " + iae);
137: iae.printStackTrace();
138: } catch (InstantiationException ie) {
139: System.err
140: .println("classmenuideadapter: class tried to\n"
141: + "instantiate represents an abstract class, an interface,"
142: + "an array class, a primitive type, or void; or if the"
143: + "instantiation fails for some other reason.");
144: System.err.println("The exception was: " + ie);
145: ie.printStackTrace();
146: } catch (SecurityException se) {
147: System.err
148: .println("classmenuideadapter: no permission to create"
149: + "a new instance");
150: System.err.println("The exception was: " + se);
151: se.printStackTrace();
152: }
153:
154: }
155:
156: }
|