Source code: org/aspectj/tools/ajde/jbuilder/AJEnableAjdeAction.java
1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 *
4 * This file is part of the IDE support for the AspectJ(tm)
5 * programming language; see http://aspectj.org
6 *
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License at
10 * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
16 *
17 * The Original Code is AspectJ.
18 *
19 * The Initial Developer of the Original Code is Xerox Corporation. Portions
20 * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21 * All Rights Reserved.
22 *
23 * Contributor(s):
24 */
25
26 package org.aspectj.tools.ajde.jbuilder;
27
28 import javax.swing.*;
29 import java.awt.*;
30 import java.awt.event.*;
31 import java.util.*;
32 import java.io.*;
33 import com.borland.primetime.ide.*;
34 import com.borland.primetime.actions.*;
35 import com.borland.primetime.ui.DefaultDialog;
36 import com.borland.primetime.node.*;
37 import com.borland.jbuilder.node.*;
38 import com.borland.primetime.editor.*;
39 import com.borland.primetime.ide.*;
40 import com.borland.primetime.viewer.*;
41 import com.borland.jbuilder.runtime.*;
42 import com.borland.primetime.runtime.*;
43 import com.borland.primetime.util.VetoException;
44 import com.borland.primetime.vfs.Url;
45 import org.aspectj.ajde.*;
46 import org.aspectj.ajde.ui.*;
47 import org.aspectj.ajde.ui.swing.*;
48
49 /**
50 * @author Mik Kersten
51 */
52 public class AJEnableAjdeAction extends BrowserAction {
53
54 private ActionGroup jbuilderBuildGroup;
55
56 public AJEnableAjdeAction() {
57 super(
58 "Start AJDE",
59 'H',
60 "Start the AspectJ Development Environment (AJDE)",
61 JBuilderManager.getJBuilderIconRegistry().getStartAjdeIcon()
62 );
63 }
64
65 public void actionPerformed(Browser browser) {
66 try {
67 if (!JBuilderManager.INSTANCE.isEnabled()) {
68 JBuilderManager.INSTANCE.init();
69 if (Browser.getActiveBrowser().getActiveProject() == null ) {
70 Ajde.getDefault().getErrorHandler().handleError("At least one project must be opened before starting AJDE.");
71 return;
72 }
73 JBuilderManager.INSTANCE.updateStructureView();
74 browser.addStaticBrowserListener(Listeners.IDE_LISTENER);
75 browser.getActiveProject().addProjectListener(Listeners.PROJECT_LISTENER);
76
77 this.setSmallIcon(AjdeUIManager.getDefault().getIconRegistry().getStopAjdeIcon());
78 this.setShortText("Stop AJDE");
79 this.setLongText("Stop the AspectJ Development Environment (AJDE)");
80 JBuilderManager.INSTANCE.setEnabled(true);
81
82 Ajde.getDefault().getConfigurationManager().setActiveConfigFile(
83 JBuilderManager.INSTANCE.getProjectProperties().getLastActiveBuildConfigFile());
84
85 Install.ajBrowserAction.setEnabled(true);
86 Install.ajOptionsAction.setEnabled(true);
87 Install.ajcCompileActionsGroup.setEnabled(true);
88 Install.installKeybindings();
89
90 JBuilderManager.INSTANCE.updateCompileActions();
91 if (Browser.getActiveBrowser().getActiveNode() != null) {
92 Ajde.getDefault().getStructureViewManager().fireNavigationAction(Browser.getActiveBrowser().getActiveNode().getLongDisplayName(), 1);
93 }
94 disableJBuilderCompilation();
95
96 if (JBuilderManager.INSTANCE.getCurrGutter() != null) {
97 JBuilderManager.INSTANCE.getCurrGutter().addGutterListener(Listeners.GUTTER_LISTENER);
98 JBuilderManager.INSTANCE.updateInlineAnnotations();
99 }
100 } else {
101 Browser.getActiveBrowser().setStructurePaneVisible(false);
102 browser.removeStaticBrowserListener(Listeners.IDE_LISTENER);
103 JBuilderManager.INSTANCE.setEnabled(false);
104 this.setSmallIcon(AjdeUIManager.getDefault().getIconRegistry().getStartAjdeIcon());
105 this.setShortText("Start AJDE");
106 this.setLongText("Start the AspectJ Development Environment (AJDE)");
107 Node node = Browser.getActiveBrowser().getActiveNode();
108 Install.uninstallKeybindings();
109 JBuilderManager.INSTANCE.saveAll();
110 try {
111 if (node != null) {
112 Browser.getActiveBrowser().closeNode(node);
113 Browser.getActiveBrowser().setStructurePaneVisible(true);
114 Browser.getActiveBrowser().doOpen(((FileNode)node).getUrl(), Browser.getActiveBrowser().getActiveProject(), false);
115 }
116 } catch (Exception e) { }
117 Install.ajcCompileActionsGroup.removeAll();
118 Install.ajcCompileActionsGroup.add(Install.NOT_STARTED_BUILD_ACTION);
119 Install.ajBrowserAction.disable();
120 enableJBuilderCompilation();
121 }
122 } catch (Throwable t) {
123 t.printStackTrace();
124 Ajde.getDefault().getErrorHandler().handleError("Could not toggle AJDE integration.", t);
125 }
126 }
127
128 private void disableJBuilderCompilation() {
129 Browser.getActiveBrowser().getActiveProject().setProperty("sys", "CompileOnRun", "0");
130 Browser.getActiveBrowser().getActiveProject().setProperty("sys", "CompileOnDebug", "0");
131 ActionGroup[] toolBars = Browser.getActiveBrowser().getToolBarGroups();
132 for (int i = 0; i < toolBars.length; i++) {
133 if (toolBars[i].getShortText().equals("Build")) {
134 jbuilderBuildGroup = toolBars[i];
135 Browser.getActiveBrowser().removeToolBarGroup(jbuilderBuildGroup);
136 }
137 }
138 JBuilderManager.INSTANCE.saveAll();
139 }
140
141 private void enableJBuilderCompilation() {
142 if (jbuilderBuildGroup == null) return;
143 Browser.getActiveBrowser().addToolBarGroup(Browser.getActiveBrowser().getToolBarGroups().length-3,
144 jbuilderBuildGroup);
145 }
146 }