001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.ide.elixir;
053:
054: /*<Imports>*/
055: import com.elixirtech.fx.FrameManager;
056: import com.elixirtech.fx.ViewManager;
057: import com.elixirtech.fx.IViewSite;
058: import com.elixirtech.fx.SettingManager;
059: import com.elixirtech.extension.IExtension;
060: import com.elixirtech.msg.Message;
061: import com.elixirtech.msg.MsgType;
062: import com.elixirtech.msg.ApplicationBus;
063: import com.elixirtech.ide.project.Folder;
064: import org.acm.seguin.tools.RefactoryInstaller;
065: import org.acm.seguin.ide.common.SingleDirClassDiagramReloader;
066: import net.sourceforge.jrefactory.uml.loader.ReloaderSingleton;
067: import org.acm.seguin.ide.common.SourceBrowser;
068:
069: /*</Imports>*/
070:
071: /**
072: * Refactory extension loads the refactory tool into memory
073: *
074: *@author Chris Seguin
075: *@created April 4, 2000
076: */
077: public class RefactoryExtension extends PrettyPrinterExtension
078: implements ApplicationBus.ICard {
079: /**
080: * Stores the base directory for the source code
081: */
082: static String base;
083: private UMLDocManager manager;
084:
085: /**
086: * Gets the CardName attribute of the Refactory
087: *
088: *@return The CardName value
089: */
090: public String getCardName() {
091: return "Refactory";
092: }
093:
094: /**
095: * Gets the Name attribute of the Refactory extension
096: *
097: *@return The Name value
098: */
099: public String getName() {
100: return "Refactory";
101: }
102:
103: /**
104: * Removes the extension mechanism
105: *
106: *@return Always returns true
107: */
108: public boolean destroy() {
109: ApplicationBus.removeCard(this );
110: return super .destroy();
111: }
112:
113: /**
114: * Initializes the extension
115: *
116: *@param args the arguments
117: *@return true if installed
118: */
119: public boolean init(String[] args) {
120: FrameManager fm = FrameManager.current();
121: if (fm == null) {
122: return false;
123: }
124:
125: (new RefactoryInstaller(true)).run();
126:
127: manager = new UMLDocManager();
128: fm.addDocManager(manager);
129:
130: Folder.addOpenFileFilter(".uml", "Class Diagrams (*.uml)");
131:
132: ApplicationBus.addCard(this );
133:
134: boolean result = super .init(args);
135:
136: ZoomDiagram.tenPercent();
137: new UndoMenuItem();
138: new ElixirClassDiagramLoader();
139: try {
140: new ElixirExtractMethod();
141: } catch (Exception exc) {
142: }
143:
144: SourceBrowser.set(new ElixirSourceBrowser());
145:
146: FrameManager
147: .current()
148: .addMenuItem(
149: "Script|JRefactory|Extract Method=((method \"extractMethod\" \"org.acm.seguin.ide.elixir.ElixirExtractMethod\"))");
150: FrameManager
151: .current()
152: .addMenuItem(
153: "Script|JRefactory|Reload Diagrams=((method \"reload\" \"org.acm.seguin.ide.elixir.ElixirClassDiagramLoader\"))");
154: FrameManager
155: .current()
156: .addMenuItem(
157: "Script|JRefactory|Undo Refactoring=((method \"undo\" \"org.acm.seguin.ide.elixir.UndoMenuItem\"))");
158: FrameManager
159: .current()
160: .addMenuItem(
161: "Script|JRefactory|Zoom|10%=((method \"tenPercent\" \"org.acm.seguin.ide.elixir.ZoomDiagram\"))");
162: FrameManager
163: .current()
164: .addMenuItem(
165: "Script|JRefactory|Zoom|25%=((method \"twentyfivePercent\" \"org.acm.seguin.ide.elixir.ZoomDiagram\"))");
166: FrameManager
167: .current()
168: .addMenuItem(
169: "Script|JRefactory|Zoom|50%=((method \"fiftyPercent\" \"org.acm.seguin.ide.elixir.ZoomDiagram\"))");
170: FrameManager
171: .current()
172: .addMenuItem(
173: "Script|JRefactory|Zoom|100%=((method \"fullSize\" \"org.acm.seguin.ide.elixir.ZoomDiagram\"))");
174: FrameManager
175: .current()
176: .addMenuItem(
177: "Script|JRefactory|About JRefactory=((method \"run\" \"org.acm.seguin.awt.AboutBox\"))");
178:
179: return result;
180: }
181:
182: /**
183: * Listener for GUI change events
184: *
185: *@param msg the message
186: */
187: public void update(Message msg) {
188: SingleDirClassDiagramReloader reloader = manager.getReloader();
189: MsgType type = msg.getType();
190: if (type == MsgType.PROJECT_OPENED) {
191: RefactoryExtension.base = SettingManager
192: .getSetting("WorkRoot");
193: reloader.setRootDirectory(RefactoryExtension.base);
194: Thread anonymous = new Thread() {
195: /**
196: * Main processing method for the RefactoryExtension object
197: */
198: public void run() {
199: ReloaderSingleton.reload();
200: }
201: };
202: anonymous.start();
203: } else if (type == MsgType.PROJECT_CLOSED) {
204: reloader.clear();
205: } else if (type == MsgType.DOCUMENT_OPENED) {
206: if (msg.getData() instanceof UMLViewManager) {
207: UMLViewManager view = (UMLViewManager) msg.getData();
208: reloader.add(view.getDiagram());
209: }
210: } else if (type == MsgType.DOCUMENT_CLOSED) {
211: if (msg.getData() instanceof UMLViewManager) {
212: UMLViewManager view = (UMLViewManager) msg.getData();
213: reloader.remove(view.getDiagram());
214: }
215: }
216: }
217:
218: /**
219: * Opportunity to veto a message
220: *
221: *@param msg the message
222: */
223: public void veto(Message msg) {
224: // no veto
225: }
226: }
227: // EOF
|