Source code: org/aspectj/tools/ajde/jbuilder/Install.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 javax.swing.text.Keymap;
32 import java.util.*;
33 import java.io.*;
34 import com.borland.primetime.ide.*;
35 import com.borland.primetime.actions.*;
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.JBuilderMenu;
42 import com.borland.jbuilder.node.JBProject;
43 import com.borland.primetime.wizard.WizardManager;
44 import org.aspectj.ajde.*;
45 import org.aspectj.ajde.ui.swing.*;
46
47 /**
48 * @author Mik Kersten
49 */
50 public class Install {
51
52 private static final String STARTUP_MESSAGE =
53 "\n\nAspectJ Development Environment (AJDE) support "
54 + org.aspectj.compiler.Version.text
55 + " loaded.\n"
56 + "Copyright (C) 2002 Xerox Corporation. All rights reserved.\n";
57
58 static ActionGroup ajdeActionsGroup = new ActionGroup("AspectJ", 'H', true);
59 static BrowserAction ajEnableAjdeAction;
60 static AJBrowserAction ajBrowserAction;
61 static AJAction ajOptionsAction;
62
63 public static AJBuildActionGroup ajcCompileActionsGroup
64 = new AJBuildActionGroup();
65 public static ActionPopupMenu compilePopupMenu = null;
66
67 static final BuildConfigNodeViewerFactory cfnvFactory = new BuildConfigNodeViewerFactory();
68
69 public static void initOpenTool(byte majorVersion, byte minorVersion) {
70 try {
71 if (minorVersion < 1) {
72 System.err.println("AJDE Error: AspectJ Development Environment (AJDE) requires JBuiler 4 or grater.");
73 } else {
74 ajdeActionsGroup.setPopup(true);
75 ajcCompileActionsGroup.add(NOT_STARTED_BUILD_ACTION);
76
77 ajdeActionsGroup.setEnabled(false);
78 //compilePopupMenu.setEnabled(false);
79
80 compilePopupMenu = new ActionPopupMenu(null, ajcCompileActionsGroup);
81
82 initActions();
83 ajdeActionsGroup.add(ajEnableAjdeAction);
84 ajdeActionsGroup.add(ajBrowserAction);
85 ajdeActionsGroup.add(ajOptionsAction);
86 ajdeActionsGroup.add(ajcCompileActionsGroup);
87
88 ProjectView.registerContextActionProvider(new ContextActionProvider() {
89 public Action getContextAction(Browser browser, Node[] nodes) {
90 for (int i=0; i<nodes.length; i++) {
91 if (!(nodes[i] instanceof JBProject))
92 return null;
93 }
94 return ajdeActionsGroup;
95 }
96 });
97
98 Browser.addToolBarGroup(Browser.getToolBarGroupCount(), ajdeActionsGroup);
99 JBuilderMenu.GROUP_Tools.add(ajdeActionsGroup);
100
101 Browser.registerNodeViewerFactory(cfnvFactory);
102
103 System.out.println(STARTUP_MESSAGE);
104 }
105 } catch (Exception e) {
106 System.err.println("AJDE Error: could not install as OpenTool");
107 e.printStackTrace();
108 }
109 }
110
111 public static void initActions() {
112 ajEnableAjdeAction = new AJEnableAjdeAction();
113 ajBrowserAction = new AJBrowserAction();
114 ajOptionsAction = new AJOptionsAction();
115 }
116
117 public static BrowserAction NOT_STARTED_BUILD_ACTION = new BrowserAction("Click 'AJ' to start AJDE and build...") {
118 public void actionPerformed(Browser browser) { }
119 };
120
121 static void installKeybindings() {
122 Keymap keymap = EditorManager.getKeymap();
123 if (keymap != null) {
124 keymap.addActionForKeyStroke(
125 KeyStroke.getKeyStroke(
126 KeyEvent.VK_F11,
127 java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
128 BUILD_KeyboardShortcut);
129 EditorActions.addBindableEditorAction(BUILD_KeyboardShortcut);
130 EditorActions.addBindableIdeAction(BUILD_KeyboardShortcut);
131 } else {
132 Ajde.getDefault().getErrorHandler().handleError("Could not install key bindings");
133 }
134 }
135
136 static void uninstallKeybindings() {
137 Keymap keymap = EditorManager.getKeymap();
138 if (keymap != null) {
139 keymap.removeKeyStrokeBinding(
140 KeyStroke.getKeyStroke(
141 KeyEvent.VK_F11,
142 java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
143 EditorActions.removeBindableEditorAction(BUILD_KeyboardShortcut);
144 EditorActions.removeBindableIdeAction(BUILD_KeyboardShortcut);
145 } else {
146 System.err.println("> AJDE Error: couldn't uninstall keymap");
147 }
148 }
149
150 public static final EditorAction BUILD_KeyboardShortcut =
151 new EditorAction("AJDE Build Shortcut") {
152 public void actionPerformed(ActionEvent e) {
153 ajcCompileActionsGroup.getAction(ajcCompileActionsGroup.getDefaultAction()).actionPerformed(e);
154 }
155 };
156 }