diff options
author | Andy Clement <aclement@pivotal.io> | 2019-01-29 16:48:39 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-01-29 16:48:39 -0800 |
commit | be07484b4a9da8ba8399080c182bf095ba62a2fe (patch) | |
tree | a30608f5ccb2b9c8dd92834f74ab16b22937b6af /ajde/src/main/java/org | |
parent | e770fb965370b4c4daf15b3e0f03b8ce77f75c0c (diff) | |
download | aspectj-be07484b4a9da8ba8399080c182bf095ba62a2fe.tar.gz aspectj-be07484b4a9da8ba8399080c182bf095ba62a2fe.zip |
mavenizing ajde - wip
Diffstat (limited to 'ajde/src/main/java/org')
140 files changed, 8925 insertions, 0 deletions
diff --git a/ajde/src/main/java/org/aspectj/ajde/Ajde.java b/ajde/src/main/java/org/aspectj/ajde/Ajde.java new file mode 100644 index 000000000..2e25e50fc --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/Ajde.java @@ -0,0 +1,489 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + *******************************************************************/ + +package org.aspectj.ajde; + +import java.awt.Frame; +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import javax.swing.JOptionPane; + +import org.aspectj.ajde.core.AjCompiler; +import org.aspectj.ajde.core.IBuildProgressMonitor; +import org.aspectj.ajde.core.ICompilerConfiguration; +import org.aspectj.ajde.internal.BuildConfigListener; +import org.aspectj.ajde.internal.BuildConfigManager; +import org.aspectj.ajde.internal.LstBuildConfigManager; +import org.aspectj.ajde.ui.FileStructureView; +import org.aspectj.ajde.ui.StructureSearchManager; +import org.aspectj.ajde.ui.StructureViewManager; +import org.aspectj.ajde.ui.swing.BrowserViewManager; +import org.aspectj.ajde.ui.swing.OptionsFrame; +import org.aspectj.ajde.ui.swing.StructureViewPanel; +import org.aspectj.ajde.ui.swing.SwingTreeViewNodeFactory; +import org.aspectj.ajde.ui.swing.TreeViewBuildConfigEditor; +import org.aspectj.asm.AsmManager; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; +import org.aspectj.util.LangUtil; +import org.aspectj.util.Reflection; + +/** + * Singleton class used to initialize the Ajde ui as well as the properties required to run the compiler. Users must call + * "Ajde.init(...)" before doing anything else. There are getter methods for the various properties that are set in the + * initialization. + * + * This also defines the factory for getting new AjCompiler instances. + * + * @author Mik Kersten + * @author Andy Clement + */ +public class Ajde { + + protected static final Ajde INSTANCE = new Ajde(); + private BrowserViewManager viewManager = null; + + private IdeUIAdapter ideUIAdapter = null; + private TreeViewBuildConfigEditor buildConfigEditor = null; + private IconRegistry iconRegistry; + private IRuntimeProperties runtimeProperties; + private boolean initialized = false; + private AsmManager asm; + private OptionsFrame optionsFrame = null; + private Frame rootFrame = null; + private StructureViewPanel fileStructurePanel = null; + + private EditorAdapter editorAdapter; + private StructureViewManager structureViewManager; + private StructureSearchManager structureSearchManager; + private final BuildConfigManager configurationManager; + + // all to do with building.... + private ICompilerConfiguration compilerConfig; + private IUIBuildMessageHandler uiBuildMsgHandler; + private IBuildProgressMonitor buildProgressMonitor; + private AjCompiler compiler; + + public AsmManager getModel() { + return asm; + } + + /** + * This class can only be constructured by itself (as a singleton) or by sub-classes. + */ + protected Ajde() { + configurationManager = new LstBuildConfigManager(); + } + + /** + * Initializes the ajde ui and sets up the compiler + */ + public void init(ICompilerConfiguration compilerConfig, IUIBuildMessageHandler uiBuildMessageHandler, + IBuildProgressMonitor monitor, EditorAdapter editorAdapter, IdeUIAdapter ideUIAdapter, IconRegistry iconRegistry, + Frame rootFrame, IRuntimeProperties runtimeProperties, boolean useFileView) { + try { + + INSTANCE.compilerConfig = compilerConfig; + INSTANCE.uiBuildMsgHandler = uiBuildMessageHandler; + INSTANCE.buildProgressMonitor = monitor; + INSTANCE.asm = AsmManager.createNewStructureModel(Collections.<File,String>emptyMap()); + + INSTANCE.iconRegistry = iconRegistry; + INSTANCE.ideUIAdapter = ideUIAdapter; + INSTANCE.buildConfigEditor = new TreeViewBuildConfigEditor(); + INSTANCE.rootFrame = rootFrame; + INSTANCE.runtimeProperties = runtimeProperties; + + INSTANCE.configurationManager.addListener(INSTANCE.STRUCTURE_UPDATE_CONFIG_LISTENER); + INSTANCE.ideUIAdapter = ideUIAdapter; + INSTANCE.editorAdapter = editorAdapter; + INSTANCE.structureSearchManager = new StructureSearchManager(); + INSTANCE.structureViewManager = new StructureViewManager(new SwingTreeViewNodeFactory(iconRegistry)); + + if (useFileView) { + FileStructureView structureView = structureViewManager.createViewForSourceFile(editorAdapter.getCurrFile(), + structureViewManager.getDefaultViewProperties()); + structureViewManager.setDefaultFileView(structureView); + fileStructurePanel = new StructureViewPanel(structureView); + } + + viewManager = new BrowserViewManager(); + optionsFrame = new OptionsFrame(iconRegistry); + + initialized = true; + } catch (Throwable t) { + Message error = new Message("AJDE UI failed to initialize", IMessage.ABORT, t, null); + uiBuildMsgHandler.handleMessage(error); + } + } + + public void showOptionsFrame() { + int x = (rootFrame.getWidth() / 2) + rootFrame.getX() - optionsFrame.getWidth() / 2; + int y = (rootFrame.getHeight() / 2) + rootFrame.getY() - optionsFrame.getHeight() / 2; + optionsFrame.setLocation(x, y); + optionsFrame.setVisible(true); + } + + /** + * @return true if init(..) has been run, false otherwise + */ + public boolean isInitialized() { + return initialized; + } + + private final BuildConfigListener STRUCTURE_UPDATE_CONFIG_LISTENER = new BuildConfigListener() { + public void currConfigChanged(String configFilePath) { + if (configFilePath != null) { + Ajde.getDefault().asm.readStructureModel(configFilePath); + } + } + + public void configsListUpdated(List configsList) { + } + }; + + /** + * Utility to run the project main class from the project properties in the same VM using a class loader populated with the + * classpath and output path or jar. Errors are logged to the ErrorHandler. + * + * @param project the ProjectPropertiesAdapter specifying the main class, classpath, and executable arguments. + * @return Thread running with process, or null if unable to start + */ + public Thread runInSameVM() { + final RunProperties props = new RunProperties(compilerConfig, runtimeProperties, uiBuildMsgHandler, rootFrame); + if (!props.valid) { + return null; // error already handled + } + Runnable runner = new Runnable() { + public void run() { + try { + Reflection.runMainInSameVM(props.classpath, props.mainClass, props.args); + } catch (Throwable e) { + Message msg = new Message("Error running " + props.mainClass, IMessage.ERROR, e, null); + uiBuildMsgHandler.handleMessage(msg); + } + } + }; + Thread result = new Thread(runner, props.mainClass); + result.start(); + return result; + } + + /** + * Utility to run the project main class from the project properties in a new VM. Errors are logged to the ErrorHandler. + * + * @return LangUtil.ProcessController running with process, or null if unable to start + */ + public LangUtil.ProcessController runInNewVM() { + final RunProperties props = new RunProperties(compilerConfig, runtimeProperties, uiBuildMsgHandler, rootFrame); + if (!props.valid) { + return null; // error already handled + } + // setup to run asynchronously, pipe streams through, and report errors + final StringBuffer command = new StringBuffer(); + LangUtil.ProcessController controller = new LangUtil.ProcessController() { + public void doCompleting(Throwable thrown, int result) { + LangUtil.ProcessController.Thrown any = getThrown(); + if (!any.thrown && (null == thrown) && (0 == result)) { + return; // no errors + } + // handle errors + String context = props.mainClass + " command \"" + command + "\""; + if (null != thrown) { + String m = "Exception running " + context; + uiBuildMsgHandler.handleMessage(new Message(m, IMessage.ERROR, thrown, null)); + } else if (0 != result) { + String m = "Result of running " + context; + uiBuildMsgHandler.handleMessage(new Message(m, IMessage.ERROR, null, null)); + } + if (null != any.fromInPipe) { + String m = "Error processing input pipe for " + context; + uiBuildMsgHandler.handleMessage(new Message(m, IMessage.ERROR, thrown, null)); + } + if (null != any.fromOutPipe) { + String m = "Error processing output pipe for " + context; + uiBuildMsgHandler.handleMessage(new Message(m, IMessage.ERROR, thrown, null)); + } + if (null != any.fromErrPipe) { + String m = "Error processing error pipe for " + context; + uiBuildMsgHandler.handleMessage(new Message(m, IMessage.ERROR, thrown, null)); + } + } + }; + + controller = LangUtil.makeProcess(controller, props.classpath, props.mainClass, props.args); + + command.append(Arrays.asList(controller.getCommand()).toString()); + + // now run the process + controller.start(); + return controller; + } + + /** struct class to interpret project properties */ + private static class RunProperties { + final String mainClass; + final String classpath; + final String[] args; + final boolean valid; + private final Frame rootFrame; + + RunProperties(ICompilerConfiguration compilerConfig, IRuntimeProperties runtimeProperties, IUIBuildMessageHandler handler, + Frame rootFrame) { + // XXX really run arbitrary handler in constructor? hmm. + LangUtil.throwIaxIfNull(runtimeProperties, "runtime properties"); + LangUtil.throwIaxIfNull(compilerConfig, "compiler configuration"); + LangUtil.throwIaxIfNull(handler, "handler"); + LangUtil.throwIaxIfNull(rootFrame, "rootFrame"); + String mainClass = null; + String classpath = null; + String[] args = null; + boolean valid = false; + this.rootFrame = rootFrame; + + mainClass = runtimeProperties.getClassToExecute(); + if (LangUtil.isEmpty(mainClass)) { + showWarningMessage("No main class specified"); + } else { + StringBuffer sb = new StringBuffer(); + List outputDirs = compilerConfig.getOutputLocationManager().getAllOutputLocations(); + for (Iterator iterator = outputDirs.iterator(); iterator.hasNext();) { + File dir = (File) iterator.next(); + sb.append(dir.getAbsolutePath() + File.pathSeparator); + } + classpath = LangUtil.makeClasspath(null, compilerConfig.getClasspath(), sb.toString(), compilerConfig.getOutJar()); + if (LangUtil.isEmpty(classpath)) { + showWarningMessage("No classpath specified"); + } else { + args = LangUtil.split(runtimeProperties.getExecutionArgs()); + valid = true; + } + } + this.mainClass = mainClass; + this.classpath = classpath; + this.args = args; + this.valid = valid; + } + + private void showWarningMessage(String message) { + JOptionPane.showMessageDialog(rootFrame, message, "Warning", JOptionPane.WARNING_MESSAGE); + } + + } + + /** + * Set the build off in the same thread + * + * @param configFile + * @param buildFresh - true if want to do a full build, false otherwise + */ + public void runBuildInSameThread(String configFile, boolean buildFresh) { + AjCompiler c = getCompilerForConfigFile(configFile); + if (c == null) + return; + if (buildFresh) { + c.buildFresh(); + } else { + c.build(); + } + } + + /** + * Set the build off in a different thread. Would need to set the build off in a different thread if using a swing application + * to display the build progress. + * + * @param configFile + * @param buildFresh - true if want to do a full build, false otherwise + */ + public void runBuildInDifferentThread(String configFile, boolean buildFresh) { + AjCompiler c = getCompilerForConfigFile(configFile); + if (c == null) + return; + CompilerThread compilerThread = new CompilerThread(c, buildFresh); + compilerThread.start(); + } + + static class CompilerThread extends Thread { + + private final AjCompiler compiler; + private final boolean buildFresh; + + public CompilerThread(AjCompiler compiler, boolean buildFresh) { + this.compiler = compiler; + this.buildFresh = buildFresh; + } + + public void run() { + if (buildFresh) { + compiler.buildFresh(); + } else { + compiler.build(); + } + } + } + + // ---------- getter methods for the ui -------------- + + /** + * @return the singleton instance + */ + public static Ajde getDefault() { + return INSTANCE; + } + + /** + * @return the BrowserViewManager + */ + public BrowserViewManager getViewManager() { + return viewManager; + } + + /** + * @return the main frame + */ + public Frame getRootFrame() { + return rootFrame; + } + + /** + * @return the parent frame for the options panel + */ + public OptionsFrame getOptionsFrame() { + return optionsFrame; + } + + /** + * @return the IdeUIAdapter + */ + public IdeUIAdapter getIdeUIAdapter() { + return ideUIAdapter; + } + + /** + * @return the EditorAdapter + */ + public EditorAdapter getEditorAdapter() { + return editorAdapter; + } + + /** + * @return the TreeViewBuildConfigEditor + */ + public TreeViewBuildConfigEditor getBuildConfigEditor() { + return buildConfigEditor; + } + + /** + * @return the StructureViewPanel + */ + public StructureViewPanel getFileStructurePanel() { + return fileStructurePanel; + } + + /** + * @return the IconRegistry + */ + public IconRegistry getIconRegistry() { + return iconRegistry; + } + + /** + * @return the StructureViewManager + */ + public StructureViewManager getStructureViewManager() { + return structureViewManager; + } + + /** + * @return the StructureSearchManager + */ + public StructureSearchManager getStructureSearchManager() { + return structureSearchManager; + } + + /** + * @return the BuildConfigManager + */ + public BuildConfigManager getBuildConfigManager() { + return configurationManager; + } + + // -------------- getter methods for the compiler ------------- + + /** + * @return the ICompilerConfiguration + */ + public ICompilerConfiguration getCompilerConfig() { + return compilerConfig; + } + + /** + * @return the IUIBuildMessageHandler + */ + public IUIBuildMessageHandler getMessageHandler() { + return uiBuildMsgHandler; + } + + /** + * @return the IBuildProgressMonitor + */ + public IBuildProgressMonitor getBuildProgressMonitor() { + return buildProgressMonitor; + } + + /** + * If the provided configFile is the same as the id for the last compiler then returns that, otherwise clears the state for the + * saved compiler and creates a new one for the provided configFile + * + * @param configFile + * @return the AjCompiler with the id of the given configFile + */ + public AjCompiler getCompilerForConfigFile(String configFile) { + if (configFile == null) { + return null; + } + if ((compiler == null || !compiler.getId().equals(configFile))) { + if (compiler != null) { + // have to remove the incremental state of the previous + // compiler - this will remove it from the + // IncrementalStateManager's + // list + compiler.clearLastState(); + } + getMessageHandler().reset(); + compiler = new AjCompiler(configFile, getCompilerConfig(), getBuildProgressMonitor(), getMessageHandler()); + } + return compiler; + } + + public AsmManager getModelForConfigFile(String configFile) { + return compiler.getModel(); + // if ((compiler == null || !compiler.getId().equals(configFile))) { + // if (compiler != null) { + // // have to remove the incremental state of the previous + // // compiler - this will remove it from the + // // IncrementalStateManager's + // // list + // compiler.clearLastState(); + // } + // getMessageHandler().reset(); + // compiler = new AjCompiler(configFile, getCompilerConfig(), getBuildProgressMonitor(), getMessageHandler()); + // } + + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/EditorAdapter.java b/ajde/src/main/java/org/aspectj/ajde/EditorAdapter.java new file mode 100644 index 000000000..b601f74e3 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/EditorAdapter.java @@ -0,0 +1,75 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde; + +import java.io.IOException; +import java.util.List; + +import org.aspectj.bridge.ISourceLocation; + +/** + * @author Mik Kersten + */ +public interface EditorAdapter { + + /** + * Seek the editor to a source line in the file specified. + */ + public void showSourceLine(String filePath, int lineNumber, boolean highlight); + + /** + * Seek the editor to a SourceLocation and highlight if specified. + */ + public void showSourceLine(ISourceLocation sourceLocation, boolean highlight); + + /** + * Seek the editor to a source line in the current file. + */ + public void showSourceLine(int lineNumber, boolean highlight); + + /** + * @return full path to the file currently being edited. + */ + public String getCurrFile(); + + /** + * Save the contents of the current file being edited. + */ + public void saveContents() throws IOException; + + /** + * Paste text into the current caret position of the editor. + */ + public void pasteToCaretPos(String text); + + /** + * Implement if inline annotations are supported by the editor. Make null + * implementation if inline annotations are not supported. + * + * @param filePath path to the file that should get the annotation + * @param lineNumber line number for the annotation + * @param items list of relations to be rendered as the annotation + */ + public void showSourcelineAnnotation(String filePath, int lineNumber, List items); + + /** + * Implement if multipe editor views are supported by the editor. Make null + * implementation if multiple editor views are not supported. + * + * @param filePath path to the source file + * @param lineNumber line number of the sourceline + */ + //public void addEditorViewForSourceLine(String filePath, int lineNumber); +} diff --git a/ajde/src/main/java/org/aspectj/ajde/EditorListener.java b/ajde/src/main/java/org/aspectj/ajde/EditorListener.java new file mode 100644 index 000000000..f39cfa074 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/EditorListener.java @@ -0,0 +1,32 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde; + +import java.util.EventListener; + +/** + * Compiler listeners get notified of structure model update events. + * + * XXX remove, not used + * + * @author Mik Kersten + */ +public interface EditorListener extends EventListener { + + /** + * @param filePath full path to the current file being edited + */ + public void currentFileChanged(String filePath); +} diff --git a/ajde/src/main/java/org/aspectj/ajde/IRuntimeProperties.java b/ajde/src/main/java/org/aspectj/ajde/IRuntimeProperties.java new file mode 100644 index 000000000..9970c597e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/IRuntimeProperties.java @@ -0,0 +1,30 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde; + +/** + * Interface to enable users to specify which class to run + */ +public interface IRuntimeProperties { + + /** + * @return class which contains the main method and should + * be used to run the application + */ + public String getClassToExecute(); + + /** + * @return args which should be used as part of the execution + * of the application + */ + public String getExecutionArgs(); + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/IUIBuildMessageHandler.java b/ajde/src/main/java/org/aspectj/ajde/IUIBuildMessageHandler.java new file mode 100644 index 000000000..7e9678d22 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/IUIBuildMessageHandler.java @@ -0,0 +1,27 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde; + +import org.aspectj.ajde.core.IBuildMessageHandler; + +/** + * Extension to the IBuildMessageHandler to be used if only one BuildMessageHandler + * is going to be used for all projects/build configuration files. Provides a method + * for resetting the state of the BuildMessageHandler between compiles + */ +public interface IUIBuildMessageHandler extends IBuildMessageHandler { + + /** + * Reset the state of the message handler + */ + public void reset(); + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/IconRegistry.java b/ajde/src/main/java/org/aspectj/ajde/IconRegistry.java new file mode 100644 index 000000000..4cdec89f2 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/IconRegistry.java @@ -0,0 +1,158 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde; + +import javax.swing.*; + +import org.aspectj.ajde.ui.*; +import org.aspectj.asm.*; +import org.aspectj.asm.IProgramElement; + +/** + * Default icons. Override behavior for custom icons. + * + * @author Mik Kersten + */ +public class IconRegistry extends AbstractIconRegistry { + + //public static IconRegistry INSTANCE = null; + protected String RESOURCE_PATH = "org/aspectj/ajde/resources/"; + + private final Icon START_AJDE = makeIcon("actions/startAjde.gif"); + private final Icon STOP_AJDE = makeIcon("actions/stopAjde.gif"); + private final Icon BUILD = makeIcon("actions/build.gif"); + private final Icon DEBUG = makeIcon("actions/debug.gif"); + private final Icon EXECUTE = makeIcon("actions/execute.gif"); + private final Icon AJBROWSER = makeIcon("structure/advice.gif"); + private final Icon AJBROWSER_ENABLED = makeIcon("actions/browserEnabled.gif"); + private final Icon AJBROWSER_DISABLED = makeIcon("actions/browserDisabled.gif"); + private final Icon STRUCTURE_VIEW = makeIcon("actions/structureView.gif"); + + private final Icon HIDE_ASSOCIATIONS = makeIcon("actions/hideAssociations.gif"); + private final Icon HIDE_NON_AJ = makeIcon("actions/hideNonAJ.gif"); + private final Icon GRANULARITY = makeIcon("actions/granularity.gif"); + private final Icon AJDE_SMALL = makeIcon("actions/ajdeSmall.gif"); + + private final Icon ERROR = makeIcon("structure/error.gif"); + private final Icon WARNING = makeIcon("structure/warning.gif"); + private final Icon INFO = makeIcon("structure/info.gif"); + + private final Icon POPUP = makeIcon("actions/popup.gif"); + private final Icon FILTER = makeIcon("actions/filter.gif"); + private final Icon RELATIONS = makeIcon("actions/relations.gif"); + private final Icon ORDER = makeIcon("actions/order.gif"); + + private final Icon ZOOM_STRUCTURE_TO_FILE_MODE = makeIcon("actions/zoomStructureToFileMode.gif"); + private final Icon ZOOM_STRUCTURE_TO_GLOBAL_MODE = makeIcon("actions/zoomStructureToGlobalMode.gif"); + private final Icon SPLIT_STRUCTURE_VIEW = makeIcon("actions/splitStructureView.gif"); + private final Icon MERGE_STRUCTURE_VIEW = makeIcon("actions/mergeStructureView.gif"); + + private final Icon BACK = makeIcon("actions/back.gif"); + private final Icon FORWARD = makeIcon("actions/forward.gif"); + private final Icon SEARCH = makeIcon("actions/search.gif"); + private final Icon OPEN_CONFIG = makeIcon("actions/openConfig.gif"); + private final Icon CLOSE_CONFIG = makeIcon("actions/closeConfig.gif"); + private final Icon SAVE = makeIcon("actions/save.gif"); + private final Icon SAVE_ALL = makeIcon("actions/saveAll.gif"); + private final Icon BROWSER_OPTIONS = makeIcon("actions/browseroptions.gif"); + + private final Icon ACCESSIBILITY_PUBLIC = makeIcon("structure/accessibility-public.gif"); + private final Icon ACCESSIBILITY_PACKAGE = makeIcon("structure/accessibility-package.gif"); + private final Icon ACCESSIBILITY_PROTECTED = makeIcon("structure/accessibility-protected.gif"); + private final Icon ACCESSIBILITY_PRIVATE = makeIcon("structure/accessibility-private.gif"); + private final Icon ACCESSIBILITY_PRIVILEGED = makeIcon("structure/accessibility-privileged.gif"); + + public Icon getAjdeSmallIcon() { return AJDE_SMALL; } + public Icon getHideAssociationsIcon() { return HIDE_ASSOCIATIONS; } + public Icon getHideNonAJIcon() { return HIDE_NON_AJ; } + public Icon getGranularityIcon() { return GRANULARITY; } + public Icon getErrorIcon() { return ERROR; } + public Icon getWarningIcon() { return WARNING; } + public Icon getInfoIcon() { return INFO; } + public Icon getAJBrowserIcon() { return AJBROWSER; } + public Icon getAJBrowserEnabledIcon() { return AJBROWSER_ENABLED; } + public Icon getAJBrowserDisabledIcon() { return AJBROWSER_DISABLED; } + public Icon getPopupIcon() { return POPUP; } + public Icon getFilterIcon() { return FILTER; } + public Icon getOrderIcon() { return ORDER; } + public Icon getRelationsIcon() { return RELATIONS; } + public Icon getStartAjdeIcon() { return START_AJDE; } + public Icon getStopAjdeIcon() { return STOP_AJDE; } + public Icon getBackIcon() { return BACK; } + public Icon getForwardIcon() { return FORWARD; } + public Icon getSearchIcon() { return SEARCH; } + public Icon getBuildIcon() { return BUILD; } + public Icon getDebugIcon() { return DEBUG; } + public Icon getExecuteIcon() { return EXECUTE; } + public Icon getOpenConfigIcon() { return OPEN_CONFIG; } + public Icon getCloseConfigIcon() { return CLOSE_CONFIG; } + public Icon getOpenIcon() { return OPEN_CONFIG; } + public Icon getSaveIcon() { return SAVE; } + public Icon getSaveAllIcon() { return SAVE_ALL; } + public Icon getBrowserOptionsIcon() { return BROWSER_OPTIONS; } + public Icon getZoomStructureToFileModeIcon() { return ZOOM_STRUCTURE_TO_FILE_MODE; } + public Icon getZoomStructureToGlobalModeIcon() { return ZOOM_STRUCTURE_TO_GLOBAL_MODE; } + public Icon getSplitStructureViewIcon() { return SPLIT_STRUCTURE_VIEW; } + public Icon getMergeStructureViewIcon() { return MERGE_STRUCTURE_VIEW; } + public Icon getStructureViewIcon() { return STRUCTURE_VIEW; } + + public Icon getAssociationSwingIcon(IRelationship.Kind relation) { + return convertToSwingIcon(getIcon(relation)); + } + + public AbstractIcon getStructureIcon(IProgramElement.Kind kind, IProgramElement.Accessibility accessibility) { + return getIcon(kind); + } + + public Icon getStructureSwingIcon(IProgramElement.Kind kind, IProgramElement.Accessibility accessibility) { + return convertToSwingIcon(getStructureIcon(kind, accessibility)); + } + + public Icon getStructureSwingIcon(IProgramElement.Kind kind) { + return convertToSwingIcon(getIcon(kind)); + } + + public Icon getAccessibilitySwingIcon(IProgramElement.Accessibility accessibility) { + if (accessibility == IProgramElement.Accessibility.PUBLIC) { + return ACCESSIBILITY_PUBLIC; + } else if (accessibility == IProgramElement.Accessibility.PACKAGE) { + return ACCESSIBILITY_PACKAGE; + } else if (accessibility == IProgramElement.Accessibility.PROTECTED) { + return ACCESSIBILITY_PROTECTED; + } else if (accessibility == IProgramElement.Accessibility.PRIVATE) { + return ACCESSIBILITY_PRIVATE; + } else if (accessibility == IProgramElement.Accessibility.PRIVILEGED) { + return ACCESSIBILITY_PRIVILEGED; + } else { + return null; + } + } + + public Icon convertToSwingIcon(AbstractIcon iconAdapter) { + if (iconAdapter != null) { + return (Icon)iconAdapter.getIconResource(); + } else { + return null; + } + } + + protected AbstractIcon createIcon(String path) { + return new AbstractIcon(new ImageIcon(ClassLoader.getSystemResource(path))); + } + + protected Icon makeIcon(String iconPath) { + return new ImageIcon(ClassLoader.getSystemResource(RESOURCE_PATH + iconPath)); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/IdeUIAdapter.java b/ajde/src/main/java/org/aspectj/ajde/IdeUIAdapter.java new file mode 100644 index 000000000..9c526fb0d --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/IdeUIAdapter.java @@ -0,0 +1,23 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde; + +/** + * @author Mik Kersten + */ +public interface IdeUIAdapter { + + public void displayStatusInformation(String message); +} diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/BuildConfigListener.java b/ajde/src/main/java/org/aspectj/ajde/internal/BuildConfigListener.java new file mode 100644 index 000000000..30d3f1e35 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/internal/BuildConfigListener.java @@ -0,0 +1,37 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + + +package org.aspectj.ajde.internal; + +import java.util.EventListener; +import java.util.List; + +/** + * @author Mik Kersten + */ +public interface BuildConfigListener extends EventListener { + + /** + * Called when the current configuration has changed. + * + * @param configFilePath the path to the new current configuration file + */ + public void currConfigChanged(String configFilePath); + + /** + * Called when items are added to or deleted from the configurations list. + */ + public void configsListUpdated(List configsList); +} diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/BuildConfigManager.java b/ajde/src/main/java/org/aspectj/ajde/internal/BuildConfigManager.java new file mode 100644 index 000000000..f049357c5 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/internal/BuildConfigManager.java @@ -0,0 +1,99 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.internal; + +import java.util.List; + +import org.aspectj.ajde.ui.BuildConfigModel; + +/** + * @author Mik Kersten + */ +public interface BuildConfigManager { + + public static final String CONFIG_FILE_SUFFIX = ".lst"; + + public static final String DEFAULT_CONFIG_LABEL = "<all project files>"; + + /** + * Returns the currently active build configuration file. The current active + * build configuration file that is set in this class is used for building and + * for updating the structure model. + * + * @return full path to the file + */ + public String getActiveConfigFile(); + + /** + * Sets the currently active build configuration file. + * + * @param full path to the file + */ + public void setActiveConfigFile(String currConfigFilePath); + + /** + * Add a listner that will be notified of build configuration change events + */ + public void addListener(BuildConfigListener configurationListener); + + /** + * Remove a configuration listener. + */ + public void removeListener(BuildConfigListener configurationListener); + + /** + * Build a model for the corresponding configuration file. + * + * @param full path to the file + */ + public BuildConfigModel buildModel(String configFilePath); + + /** + * Save the given configuration model to the file that it was generated from. + */ + public void writeModel(BuildConfigModel model); + + /** + * Write a list of source files into a configuration file. File paths will be + * written relative to the path of the configuration file. + */ + public void writePaths(String configFilePath, List paths); + + /** + * Add files to a configuration. + * + * @param configFilePath full path to the configuration file + * @param files list of full paths to the files to be added + */ + public void addFilesToConfig(String configFilePath, List files); + + /** + * Remove files from a configuration. + * + * @param configFilePath full path to the configuration file + * @param files list of full paths to the files to be removed + */ + public void removeFilesFromConfig(String configFilePath, List files); + + + /** + * @return list (of Strings) of all build configuration files + * found so far + */ + public List /*String*/ getAllBuildConfigFiles(); + +} + + diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileParser.java b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileParser.java new file mode 100644 index 000000000..7eb195716 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileParser.java @@ -0,0 +1,57 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.ajde.internal; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.aspectj.ajdt.ajc.ConfigParser; + +/** + * @author Mik Kersten + */ +public class LstBuildConfigFileParser extends ConfigParser { + + private List<File> importedFiles = new ArrayList<File>(); + private List<String> problemEntries = new ArrayList<String>(); + + // private String currFilePath; + + public LstBuildConfigFileParser(String currFilePath) { + // this.currFilePath = currFilePath; + } + + protected void showWarning(String message) { + problemEntries.add(message); + } + + protected void parseImportedConfigFile(String relativeFilePath) { + importedFiles.add(makeFile(relativeFilePath)); + super.files.add(new File(relativeFilePath)); + super.parseImportedConfigFile(relativeFilePath); + } + + protected void showError(String message) { + problemEntries.add(message); + } + + public List<File> getImportedFiles() { + return importedFiles; + } + + public List<String> getProblemEntries() { + return problemEntries; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java new file mode 100644 index 000000000..24e264d70 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigFileUpdater.java @@ -0,0 +1,217 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + +package org.aspectj.ajde.internal; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.BuildConfigNode; +import org.aspectj.ajdt.ajc.ConfigParser; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * Used for reading and writing build configuration (".lst") files. + * + * @author Mik Kersten + */ +class LstBuildConfigFileUpdater { + + /** + * Adds an entry to a build configuration file. + */ + public void updateBuildConfigFile(String buildConfigFile, String update, boolean addToConfiguration) { + List fileContents = readConfigFile(buildConfigFile); + if (addToConfiguration) { + fileContents.add(update); + } else { + fileContents.remove(update); + } + writeConfigFile(buildConfigFile, fileContents); + } + + /** + * Adds an entry to multiple build configuration files. + */ + public void updateBuildConfigFiles(List buildConfigFiles, List<String> filesToUpdate, boolean addToConfiguration) { + for (int i = 0; i < buildConfigFiles.size(); i++) { + List<String> fileContents = readConfigFile((String) buildConfigFiles.get(i)); + if (addToConfiguration) { + for (int j = 0; j < filesToUpdate.size(); j++) { + fileContents.add(filesToUpdate.get(j)); + } + } else { + for (int k = 0; k < filesToUpdate.size(); k++) { + if (fileContents.contains(filesToUpdate.get(k))) { + fileContents.remove(filesToUpdate.get(k)); + } + } + } + writeConfigFile((String) buildConfigFiles.get(i), fileContents); + } + } + + /** + * Checks if an entry exists within a build configuration file. + */ + public boolean exists(String entry, String configFile) { + return exists(entry, configFile, ""); + } + + public boolean exists(String entry, String configFile, String rootPath) { + Iterator it = readConfigFile(configFile).iterator(); + while (it.hasNext()) { + if ((entry).equals(rootPath + "/" + (String) it.next())) { + return true; + } + } + return false; + } + + /** + * Reads the entries of a configuration file. + */ + public List<String> readConfigFile(String filePath) { + try { + File configFile = new File(filePath); + if (!configFile.exists()) { + Message msg = new Message("Config file: " + filePath + " does not exist. Update failed.", IMessage.WARNING, null, + null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + List<String> fileContents = new ArrayList<String>(); + BufferedReader reader = new BufferedReader(new FileReader(configFile)); + String line = reader.readLine(); + while (line != null) { + fileContents.add(line.replace('\\', '/')); + line = reader.readLine(); + } + reader.close(); + return fileContents; + } catch (IOException ioe) { + Message msg = new Message("Could not update build config file.", IMessage.ERROR, ioe, null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + return null; + } + + public void writeConfigFile(String filePath, List files, List importedNodes) { + // Set contentsSet = new TreeSet(fileContents); + String fileContentsString = ""; + // List filesToWrite = null; + Set includedFiles = new HashSet(); + for (Iterator it = importedNodes.iterator(); it.hasNext();) { + BuildConfigNode node = (BuildConfigNode) it.next(); + fileContentsString += '@' + node.getResourcePath() + "\n"; + String parentPath = new File(filePath).getParent(); + String importedFilePath = parentPath + File.separator + node.getResourcePath(); + includedFiles.addAll(getIncludedFiles(importedFilePath, parentPath)); + } + + for (Iterator it = files.iterator(); it.hasNext();) { + BuildConfigNode node = (BuildConfigNode) it.next(); + if (node.getName().endsWith(".lst") && !node.getResourcePath().startsWith("..")) { + fileContentsString += '@'; + fileContentsString += node.getResourcePath() + "\n"; + } else { + if (!includedFiles.contains(node.getResourcePath())) { + fileContentsString += node.getResourcePath() + "\n"; + } + } + } + writeFile(fileContentsString, filePath); + } + + private List<String> getIncludedFiles(String path, String rootPath) { + try { + ConfigParser configParser = new ConfigParser(); + configParser.parseConfigFile(new File(path)); + List<File> files = configParser.getFiles(); + List<String> relativeFiles = new ArrayList<String>(); + for (Iterator<File> it = files.iterator(); it.hasNext();) { + relativeFiles.add(relativizePath(((File) it.next()).getPath(), rootPath)); + } + return relativeFiles; + } catch (ConfigParser.ParseException pe) { + return new ArrayList<String>(); + } + } + + // private synchronized List getUniqueFileList(List list, Set set) { + // List uniqueList = new ArrayList(); + // for (Iterator it = list.iterator(); it.hasNext(); ) { + // BuildConfigNode node = (BuildConfigNode)it.next(); + // String file1 = node.getResourcePath(); + // if (set.contains(file1) && !uniqueList.contains(file1)) { + // uniqueList.add(file1); + // } + // } + // return uniqueList; + // } + + public String relativizePath(String path, String rootPath) { + path = path.replace('\\', '/'); + rootPath = rootPath.replace('\\', '/'); + int pathIndex = path.indexOf(rootPath); + if (pathIndex > -1) { + return path.substring(pathIndex + rootPath.length() + 1); + } else { + return path; + } + } + + /** + * Sorts and does not write duplicates. + * + * @param fileContents full paths representing file entries + */ + public void writeConfigFile(String filePath, List fileContents) { + Set contentsSet = new TreeSet(fileContents); + StringBuffer fileContentsSB = new StringBuffer(); + Iterator it = contentsSet.iterator(); + while (it.hasNext()) { + fileContentsSB.append(it.next().toString()); + fileContentsSB.append("\n"); + } + writeFile(fileContentsSB.toString(), filePath); + } + + private void writeFile(String contents, String filePath) { + FileOutputStream fos = null; + try { + fos = new FileOutputStream(filePath, false); + fos.write(contents.getBytes()); + } catch (IOException ioe) { + Message msg = new Message("Could not update build config file: " + filePath, IMessage.ERROR, ioe, null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } finally { + if (fos != null) + try { + fos.close(); + } catch (IOException ioe) { + } + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java new file mode 100644 index 000000000..05c4cc2a0 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/internal/LstBuildConfigManager.java @@ -0,0 +1,310 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + +package org.aspectj.ajde.internal; + +import java.io.File; +import java.io.FileFilter; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.BuildConfigModel; +import org.aspectj.ajde.ui.BuildConfigNode; +import org.aspectj.ajdt.ajc.ConfigParser; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; +import org.aspectj.bridge.SourceLocation; +import org.aspectj.util.FileUtil; + +/** + * @author Mik Kersten + */ +public class LstBuildConfigManager implements BuildConfigManager { + + private List<String> allBuildConfigFiles; + private List<BuildConfigListener> listeners = new ArrayList<BuildConfigListener>(); + private LstBuildConfigFileUpdater fileUpdater = new LstBuildConfigFileUpdater(); + protected String currConfigFilePath = null; + + private static final FilenameFilter SOURCE_FILE_FILTER = new FilenameFilter() { + public boolean accept(File dir, String name) { + return FileUtil.hasSourceSuffix(name) || name.endsWith(".lst"); + } + }; + + private static final FileFilter DIR_FILTER = new FileFilter() { + public boolean accept(File file) { + return file.isDirectory(); + } + }; + + public BuildConfigModel buildModel(String configFilePath) { + File configFile = new File(configFilePath); + String rootPath = configFile.getParent(); + String configFileName = configFile.getName(); + BuildConfigModel model = new BuildConfigModel(configFilePath); + List<File> configFiles = new ArrayList<File>(); + List<File> importedFiles = new ArrayList<File>(); + List<String> badEntries = null; + try { + LstBuildConfigFileParser configParser = new LstBuildConfigFileParser(configFilePath); + configParser.parseConfigFile(new File(configFilePath)); + configFiles = configParser.getFiles(); + importedFiles = configParser.getImportedFiles(); + badEntries = configParser.getProblemEntries(); + } catch (ConfigParser.ParseException pe) { + // String filePath = "<unknown>"; + // if (pe.getFile() != null) filePath = pe.getFile().getAbsolutePath(); + IMessage message = new Message(pe.getMessage(), IMessage.ERROR, pe, new SourceLocation(pe.getFile(), pe.getLine(), 1)); + Ajde.getDefault().getMessageHandler().handleMessage(message); + } + + List<String> relativePaths = relativizeFilePaths(configFiles, rootPath); + BuildConfigNode root = new BuildConfigNode(configFileName, BuildConfigNode.Kind.FILE_LST, rootPath); + buildDirTree(root, rootPath, importedFiles, configFileName); + model.setRoot(root); + addFilesToDirTree(model, relativePaths, badEntries); + + pruneEmptyDirs(root); + sortModel(model.getRoot(), ALPHABETICAL_COMPARATOR); + // addImportedFilesToDirTree(model, importedFiles); + + addProblemEntries(root, badEntries); + return model; + } + + private void addProblemEntries(BuildConfigNode root, List badEntries) { + for (Iterator it = badEntries.iterator(); it.hasNext();) { + root.addChild(new BuildConfigNode(it.next().toString(), BuildConfigNode.Kind.ERROR, null)); + } + } + + public void writeModel(BuildConfigModel model) { + // final List paths = new ArrayList(); + // StructureWalker walker = new StructureWalker() { + // protected void postProcess(StructureNode node) { + // BuildConfigNode configNode = (BuildConfigNode)node; + // if (configNode.isActive() && configNode.isValidResource()) { + // paths.add(configNode.getResourcePath()); + // } + // } + // }; + // model.getRoot().walk(walker); + + List activeSourceFiles = model.getActiveNodes(BuildConfigNode.Kind.FILE_ASPECTJ); + activeSourceFiles.addAll(model.getActiveNodes(BuildConfigNode.Kind.FILE_JAVA)); + List activeImportedFiles = model.getActiveNodes(BuildConfigNode.Kind.FILE_LST); + fileUpdater.writeConfigFile(model.getSourceFile(), activeSourceFiles, activeImportedFiles); + } + + public void writePaths(String configFilePath, List files) { + fileUpdater.writeConfigFile(configFilePath, files); + } + + public void addFilesToConfig(String configFilePath, List paths) { + + } + + public void removeFilesFromConfig(String configFilePath, List files) { + + } + + private List<String> relativizeFilePaths(List<File> configFiles, String rootPath) { + List<String> relativePathsList = new ArrayList<String>(); + for (File file : configFiles) { + relativePathsList.add(fileUpdater.relativizePath(file.getPath(), rootPath)); + } + return relativePathsList; + } + + // private String relativizePath(String path, String rootPath) { + // path = path.replace('\\', '/'); + // rootPath = rootPath.replace('\\', '/'); + // int pathIndex = path.indexOf(rootPath); + // if (pathIndex > -1) { + // return path.substring(pathIndex + rootPath.length() + 1); + // } else { + // return path; + // } + // } + + private void buildDirTree(BuildConfigNode node, String rootPath, List importedFiles, String configFileName) { + File[] dirs = new File(node.getResourcePath()).listFiles(DIR_FILTER); + if (dirs == null) + return; + for (int i = 0; i < dirs.length; i++) { + BuildConfigNode dir = new BuildConfigNode(dirs[i].getName(), BuildConfigNode.Kind.DIRECTORY, dirs[i].getPath()); + File[] files = dirs[i].listFiles(SOURCE_FILE_FILTER); + for (int j = 0; j < files.length; j++) { + if (files[j] != null) {// && !files[j].getName().endsWith(".lst")) { + String filePath = fileUpdater.relativizePath(files[j].getPath(), rootPath); + BuildConfigNode.Kind kind = BuildConfigNode.Kind.FILE_JAVA; + if (!files[j].getName().endsWith(".lst")) { + // kind = BuildConfigNode.Kind.FILE_LST; + BuildConfigNode file = new BuildConfigNode(files[j].getName(), kind, filePath); + file.setActive(false); + dir.addChild(file); + } + } + } + node.addChild(dir); + // boolean foundMatch = false; + for (Iterator it = importedFiles.iterator(); it.hasNext();) { + File importedFile = (File) it.next(); + if (importedFile.getParentFile().getAbsolutePath().equals(dirs[i].getAbsolutePath())) { + // foundMatch = true; + BuildConfigNode importedFileNode = new BuildConfigNode(importedFile.getName(), BuildConfigNode.Kind.FILE_LST, + fileUpdater.relativizePath(importedFile.getPath(), rootPath)); + importedFileNode.setActive(true); + // dir.getChildren().clear(); + boolean found = false; + for (Iterator it2 = dir.getChildren().iterator(); it2.hasNext();) { + if (((BuildConfigNode) it2.next()).getName().equals(importedFile.getName())) { + found = true; + } + } + if (!found) + dir.addChild(importedFileNode); + } + + } + // if (!foundMatch) + buildDirTree(dir, rootPath, importedFiles, configFileName); + } + + if (node.getName().endsWith(".lst")) { + File[] files = new File(rootPath).listFiles(SOURCE_FILE_FILTER); + if (files == null) + return; + for (int i = 0; i < files.length; i++) { + if (files[i] != null && !files[i].getName().equals(configFileName)) {// && !files[i].getName().endsWith(".lst")) { + BuildConfigNode.Kind kind = BuildConfigNode.Kind.FILE_JAVA; + if (files[i].getName().endsWith(".lst")) { + kind = BuildConfigNode.Kind.FILE_LST; + } + BuildConfigNode file = new BuildConfigNode(files[i].getName(), kind, files[i].getName()); + file.setActive(false); + node.addChild(file); + } + } + } + } + + private void addFilesToDirTree(BuildConfigModel model, List configFiles, List badEntries) { + for (Iterator it = configFiles.iterator(); it.hasNext();) { + String path = (String) it.next(); + if (path.startsWith("..")) { + File file = new File(path); + BuildConfigNode node = new BuildConfigNode(file.getName(), BuildConfigNode.Kind.FILE_JAVA, path); + BuildConfigNode upPath = model.getNodeForPath(file.getParentFile().getPath()); + if (upPath == model.getRoot()) { + upPath = new BuildConfigNode(file.getParentFile().getPath(), BuildConfigNode.Kind.DIRECTORY, file + .getParentFile().getAbsolutePath()); + model.getRoot().addChild(upPath); + } + node.setActive(true); + upPath.addChild(node); + } else if (!(new File(path).isAbsolute())) { + // String name = new File(path).getName(); + BuildConfigNode existingNode = model.getNodeForPath(path); + existingNode.setActive(true); + } else { + badEntries.add("Use relative paths only, omitting: " + path); + } + } + } + + private boolean pruneEmptyDirs(BuildConfigNode node) { + List nodesToRemove = new ArrayList(); + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + BuildConfigNode currNode = (BuildConfigNode) it.next(); + boolean hasValidChildren = pruneEmptyDirs(currNode); + if (!currNode.isValidResource() && !hasValidChildren) { + nodesToRemove.add(currNode); + } + } + + for (Iterator it = nodesToRemove.iterator(); it.hasNext();) { + BuildConfigNode currNode = (BuildConfigNode) it.next(); + node.removeChild(currNode); + } + return node.getChildren().size() > 0; + } + + public String getActiveConfigFile() { + return currConfigFilePath; + } + + public void setActiveConfigFile(String currConfigFilePath) { + if (currConfigFilePath == null) + return; + this.currConfigFilePath = currConfigFilePath; + notifyConfigChanged(); + } + + public void addListener(BuildConfigListener configurationListener) { + listeners.add(configurationListener); + } + + public void removeListener(BuildConfigListener configurationListener) { + listeners.remove(configurationListener); + } + + private void notifyConfigChanged() { + for (Iterator it = listeners.iterator(); it.hasNext();) { + ((BuildConfigListener) it.next()).currConfigChanged(currConfigFilePath); + } + } + + // private void notifyConfigsListUpdated() { + // for (Iterator it = listeners.iterator(); it.hasNext(); ) { + // ((BuildConfigListener)it.next()).configsListUpdated(configFiles); + // } + // } + // + private void sortModel(BuildConfigNode node, Comparator comparator) { + if (node == null || node.getChildren() == null) + return; + Collections.sort(node.getChildren(), comparator); + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + BuildConfigNode nextNode = (BuildConfigNode) it.next(); + if (nextNode != null) + sortModel(nextNode, comparator); + } + } + + private static final Comparator ALPHABETICAL_COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + BuildConfigNode n1 = (BuildConfigNode) o1; + BuildConfigNode n2 = (BuildConfigNode) o2; + return n1.getName().compareTo(n2.getName()); + } + }; + + public List<String> getAllBuildConfigFiles() { + if (allBuildConfigFiles == null) { + allBuildConfigFiles = new ArrayList<String>(); + if (getActiveConfigFile() != null) { + allBuildConfigFiles.add(getActiveConfigFile()); + } + } + return allBuildConfigFiles; + } + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/internal/StructureUtilities.java b/ajde/src/main/java/org/aspectj/ajde/internal/StructureUtilities.java new file mode 100644 index 000000000..866a5bad8 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/internal/StructureUtilities.java @@ -0,0 +1,89 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.internal; + +//import org.aspectj.ajde.compiler.AjdeCompiler; +//import org.aspectj.compiler.structure.*; +//import org.aspectj.compiler.structure.associations.*; + +/** + * Utility class for building a structure model for a given compile. Typical command-line usage: <BR> + * > <TT>java org.aspectj.tools.ajde.StructureManager @<config-file>.lst</TT> + */ +public class StructureUtilities { + +// private static StructureManager structureManager = new StructureManager(); + + /** + * Usage is the same as <CODE>org.aspectj.tools.ajc.Main</CODE>. + */ +// public static void main(String[] args) throws IOException { +// StructureNode model = buildStructureModel(args); +// if (model == null) { + +// } else { +// dumpStructure(model, ""); +// } +// } + + /** + * Compiles and builds a structure model. + * + * @return the node representing the root for the structure model + */ +// public static StructureNode buildStructureModel(String[] args) { +// new StructureBuilder().buildStructure(args); +// return structureManager.getStructureModel(); +// } + + /** + * Dumps the structure model by walking the + * corresponding tree. + * * @param node node to start traversal at, typically the root + * @param indent whitespace accumulator for pretty-printing + */ +// public static void dumpStructure(StructureNode node, String indent) { +// if (node == null) return; +// Syste.println(indent + node); +// if (node.getChildren() != null) { +// for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { +// dumpStructure((StructureNode)it.next(), indent + " "); +// } +// } +// if (node instanceof ProgramElementNode) { +// if (((ProgramElementNode)node).getRelations() != null) { +// for (Iterator it = ((ProgramElementNode)node).getRelations().iterator(); it.hasNext(); ) { +// dumpStructure((StructureNode)it.next(), indent + " "); +// } +// } +// } +// } +// +// private static class StructureBuilder extends org.aspectj.tools.ajc.Main { +// public void buildStructure(String[] args) { +// compile(args); +// } +// +// public JavaCompiler getCompiler() { +// if (compiler != null) return compiler; +// if (compiler == null) { +// if (errorHandler == null) { +// compiler = new AjdeCompiler(structureManager); +// } +// } +// return compiler; +// } +// } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/ajdeSmall.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/ajdeSmall.gif Binary files differnew file mode 100644 index 000000000..2b08761cb --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/ajdeSmall.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/back.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/back.gif Binary files differnew file mode 100644 index 000000000..06960ea56 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/back.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/browserDisabled.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/browserDisabled.gif Binary files differnew file mode 100644 index 000000000..0ed9ecac9 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/browserDisabled.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/browserEnabled.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/browserEnabled.gif Binary files differnew file mode 100644 index 000000000..876dd51f2 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/browserEnabled.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/browseroptions.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/browseroptions.gif Binary files differnew file mode 100644 index 000000000..4c8aa8d01 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/browseroptions.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/build.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/build.gif Binary files differnew file mode 100644 index 000000000..2673baa2d --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/build.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/clean.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/clean.gif Binary files differnew file mode 100644 index 000000000..9dc08247b --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/clean.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/closeConfig.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/closeConfig.gif Binary files differnew file mode 100644 index 000000000..e11d635a9 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/closeConfig.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/debug.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/debug.gif Binary files differnew file mode 100644 index 000000000..9c38140c0 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/debug.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/default.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/default.gif Binary files differnew file mode 100644 index 000000000..b1341dff4 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/default.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/execute.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/execute.gif Binary files differnew file mode 100644 index 000000000..5d7bfcc96 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/execute.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/filter.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/filter.gif Binary files differnew file mode 100644 index 000000000..b73b8fff5 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/filter.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/find.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/find.gif Binary files differnew file mode 100644 index 000000000..bca27b12a --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/find.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/forward.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/forward.gif Binary files differnew file mode 100644 index 000000000..cc7f973d2 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/forward.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/granularity.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/granularity.gif Binary files differnew file mode 100644 index 000000000..286ee1945 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/granularity.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/hideAssociations.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/hideAssociations.gif Binary files differnew file mode 100644 index 000000000..492e148e8 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/hideAssociations.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/hideNonAJ.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/hideNonAJ.gif Binary files differnew file mode 100644 index 000000000..3e1ce96ef --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/hideNonAJ.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/mergeStructureView.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/mergeStructureView.gif Binary files differnew file mode 100644 index 000000000..359d2888d --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/mergeStructureView.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/new.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/new.gif Binary files differnew file mode 100644 index 000000000..1d02decea --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/new.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/open.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/open.gif Binary files differnew file mode 100644 index 000000000..1549ecd7b --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/open.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/openConfig.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/openConfig.gif Binary files differnew file mode 100644 index 000000000..64d7028e5 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/openConfig.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/options.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/options.gif Binary files differnew file mode 100644 index 000000000..02538e940 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/options.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/order.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/order.gif Binary files differnew file mode 100644 index 000000000..67586ef30 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/order.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/outputWindow.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/outputWindow.gif Binary files differnew file mode 100644 index 000000000..9b65c6b6e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/outputWindow.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/popup.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/popup.gif Binary files differnew file mode 100644 index 000000000..3030e1954 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/popup.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/refresh.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/refresh.gif Binary files differnew file mode 100644 index 000000000..7e6bd1747 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/refresh.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/relations.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/relations.gif Binary files differnew file mode 100644 index 000000000..e091ac2b5 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/relations.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/save.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/save.gif Binary files differnew file mode 100644 index 000000000..ed704396c --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/save.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/saveAll.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/saveAll.gif Binary files differnew file mode 100644 index 000000000..18d0c9ff5 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/saveAll.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/search.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/search.gif Binary files differnew file mode 100644 index 000000000..164b9123e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/search.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/splitStructureView.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/splitStructureView.gif Binary files differnew file mode 100644 index 000000000..825dcfea7 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/splitStructureView.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/startAjde.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/startAjde.gif Binary files differnew file mode 100644 index 000000000..5c49b6a32 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/startAjde.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/stopAjde.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/stopAjde.gif Binary files differnew file mode 100644 index 000000000..97cfa4c71 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/stopAjde.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/structureView.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/structureView.gif Binary files differnew file mode 100644 index 000000000..8e2d2e7d0 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/structureView.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/zoomStructureToFileMode.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/zoomStructureToFileMode.gif Binary files differnew file mode 100644 index 000000000..0c1d83eec --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/zoomStructureToFileMode.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/actions/zoomStructureToGlobalMode.gif b/ajde/src/main/java/org/aspectj/ajde/resources/actions/zoomStructureToGlobalMode.gif Binary files differnew file mode 100644 index 000000000..98a93e096 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/actions/zoomStructureToGlobalMode.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-package.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-package.gif Binary files differnew file mode 100644 index 000000000..0c7bfc426 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-package.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-private.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-private.gif Binary files differnew file mode 100644 index 000000000..d543c82f5 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-private.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-privileged.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-privileged.gif Binary files differnew file mode 100644 index 000000000..3b65259bd --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-privileged.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-protected.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-protected.gif Binary files differnew file mode 100644 index 000000000..dd2a5f0c6 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-protected.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-public.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-public.gif Binary files differnew file mode 100644 index 000000000..45b759436 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/accessibility-public.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/advice.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/advice.gif Binary files differnew file mode 100644 index 000000000..48317f8b9 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/advice.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/adviceBack.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/adviceBack.gif Binary files differnew file mode 100644 index 000000000..81a3bb684 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/adviceBack.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/adviceForward.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/adviceForward.gif Binary files differnew file mode 100644 index 000000000..06ed1932c --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/adviceForward.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/annotation.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/annotation.gif Binary files differnew file mode 100644 index 000000000..435d62ed4 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/annotation.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/aspect.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/aspect.gif Binary files differnew file mode 100644 index 000000000..3c4bcbe43 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/aspect.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/class.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/class.gif Binary files differnew file mode 100644 index 000000000..3c5670560 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/class.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/code.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/code.gif Binary files differnew file mode 100644 index 000000000..177155246 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/code.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareError.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareError.gif Binary files differnew file mode 100644 index 000000000..1db5788e2 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareError.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareParents.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareParents.gif Binary files differnew file mode 100644 index 000000000..c768f43c8 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareParents.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/declarePrecedence.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declarePrecedence.gif Binary files differnew file mode 100644 index 000000000..b5e1ce406 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declarePrecedence.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareSoft.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareSoft.gif Binary files differnew file mode 100644 index 000000000..a78b43e4c --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareSoft.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareWarning.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareWarning.gif Binary files differnew file mode 100644 index 000000000..6f80eec9d --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/declareWarning.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/enum.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/enum.gif Binary files differnew file mode 100644 index 000000000..15535f52f --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/enum.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/error.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/error.gif Binary files differnew file mode 100644 index 000000000..964229dcc --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/error.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/field.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/field.gif Binary files differnew file mode 100644 index 000000000..2df264501 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/field.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-aspectj.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-aspectj.gif Binary files differnew file mode 100644 index 000000000..c6b3df108 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-aspectj.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-java.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-java.gif Binary files differnew file mode 100644 index 000000000..3cab52eb2 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-java.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-lst.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-lst.gif Binary files differnew file mode 100644 index 000000000..d67e52bb8 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file-lst.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/file.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file.gif Binary files differnew file mode 100644 index 000000000..53eafb09c --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/file.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/info.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/info.gif Binary files differnew file mode 100644 index 000000000..6a6d53745 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/info.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/inheritanceBack.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/inheritanceBack.gif Binary files differnew file mode 100644 index 000000000..42db4fe5e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/inheritanceBack.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/inheritanceForward.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/inheritanceForward.gif Binary files differnew file mode 100644 index 000000000..cc55b3c86 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/inheritanceForward.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/interface.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/interface.gif Binary files differnew file mode 100644 index 000000000..1b3eaec83 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/interface.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/introduction.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/introduction.gif Binary files differnew file mode 100644 index 000000000..389d1429e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/introduction.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/method.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/method.gif Binary files differnew file mode 100644 index 000000000..14308e89a --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/method.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/package.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/package.gif Binary files differnew file mode 100644 index 000000000..f9be40a97 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/package.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/pointcut.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/pointcut.gif Binary files differnew file mode 100644 index 000000000..d6e9454ac --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/pointcut.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/precedenceBack.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/precedenceBack.gif Binary files differnew file mode 100644 index 000000000..3c347653f --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/precedenceBack.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/precedenceForward.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/precedenceForward.gif Binary files differnew file mode 100644 index 000000000..51a913b6c --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/precedenceForward.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/project.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/project.gif Binary files differnew file mode 100644 index 000000000..8e2d2e7d0 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/project.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/referenceBack.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/referenceBack.gif Binary files differnew file mode 100644 index 000000000..0a8207c0e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/referenceBack.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/referenceForward.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/referenceForward.gif Binary files differnew file mode 100644 index 000000000..f5ecde63f --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/referenceForward.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/search.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/search.gif Binary files differnew file mode 100644 index 000000000..164b9123e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/search.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/resources/structure/warning.gif b/ajde/src/main/java/org/aspectj/ajde/resources/structure/warning.gif Binary files differnew file mode 100644 index 000000000..4430459ce --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/resources/structure/warning.gif diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/AbstractIcon.java b/ajde/src/main/java/org/aspectj/ajde/ui/AbstractIcon.java new file mode 100644 index 000000000..c9485c885 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/AbstractIcon.java @@ -0,0 +1,31 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +/** + * @author Mik Kersten + */ +public class AbstractIcon { + + private Object iconResource; + + public AbstractIcon(Object iconResource) { + this.iconResource = iconResource; + } + + public Object getIconResource() { + return iconResource; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/AbstractIconRegistry.java b/ajde/src/main/java/org/aspectj/ajde/ui/AbstractIconRegistry.java new file mode 100644 index 000000000..742cc1a6b --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/AbstractIconRegistry.java @@ -0,0 +1,158 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +import org.aspectj.asm.*; + +/** + * Uses the factory pattern. + * + * @author Mik Kersten + */ +public abstract class AbstractIconRegistry { + + protected final String RESOURCE_PATH = "org/aspectj/ajde/resources/"; + protected final String STRUCTURE_PATH = RESOURCE_PATH + "structure/"; + + protected final AbstractIcon PROJECT = createIcon(STRUCTURE_PATH + "project.gif"); + protected final AbstractIcon PACKAGE = createIcon(STRUCTURE_PATH + "package.gif"); + protected final AbstractIcon ASPECT = createIcon(STRUCTURE_PATH + "aspect.gif"); + protected final AbstractIcon INITIALIZER = createIcon(STRUCTURE_PATH + "code.gif"); + protected final AbstractIcon INTRODUCTION = createIcon(STRUCTURE_PATH + "introduction.gif"); + protected final AbstractIcon CONSTRUCTOR = createIcon(STRUCTURE_PATH + "method.gif"); + protected final AbstractIcon POINTCUT = createIcon(STRUCTURE_PATH + "pointcut.gif"); + protected final AbstractIcon ADVICE = createIcon(STRUCTURE_PATH + "advice.gif"); + protected final AbstractIcon DECLARE_PARENTS = createIcon(STRUCTURE_PATH + "declareParents.gif"); + protected final AbstractIcon DECLARE_WARNING = createIcon(STRUCTURE_PATH + "declareWarning.gif"); + protected final AbstractIcon DECLARE_ERROR = createIcon(STRUCTURE_PATH + "declareError.gif"); + protected final AbstractIcon DECLARE_SOFT = createIcon(STRUCTURE_PATH + "declareSoft.gif"); + protected final AbstractIcon CODE = createIcon(STRUCTURE_PATH + "code.gif"); + protected final AbstractIcon ERROR = createIcon(STRUCTURE_PATH + "error.gif"); + + protected final AbstractIcon FILE = createIcon(STRUCTURE_PATH + "file.gif"); + protected final AbstractIcon FILE_JAVA = createIcon(STRUCTURE_PATH + "file-java.gif"); + protected final AbstractIcon FILE_ASPECTJ = createIcon(STRUCTURE_PATH + "file-aspectj.gif"); + protected final AbstractIcon FILE_LST = createIcon(STRUCTURE_PATH + "file-lst.gif"); + + protected final AbstractIcon METHOD = createIcon(STRUCTURE_PATH + "method.gif"); + protected final AbstractIcon FIELD = createIcon(STRUCTURE_PATH + "field.gif"); + protected final AbstractIcon ENUM_VALUE = createIcon(STRUCTURE_PATH + "field.gif"); // ??? should be enum value icon + protected final AbstractIcon ENUM = createIcon(STRUCTURE_PATH + "enum.gif"); + protected final AbstractIcon ANNOTATION = createIcon(STRUCTURE_PATH + "annotation.gif"); + protected final AbstractIcon CLASS = createIcon(STRUCTURE_PATH + "class.gif"); + protected final AbstractIcon INTERFACE = createIcon(STRUCTURE_PATH + "interface.gif"); + + protected final AbstractIcon RELATION_ADVICE_FORWARD = createIcon(STRUCTURE_PATH + "adviceForward.gif"); + protected final AbstractIcon RELATION_ADVICE_BACK = createIcon(STRUCTURE_PATH + "adviceBack.gif"); + protected final AbstractIcon RELATION_INHERITANCE_FORWARD = createIcon(STRUCTURE_PATH + "inheritanceForward.gif"); + protected final AbstractIcon RELATION_INHERITANCE_BACK = createIcon(STRUCTURE_PATH + "inheritanceBack.gif"); + protected final AbstractIcon RELATION_REFERENCE_FORWARD = createIcon(STRUCTURE_PATH + "referenceForward.gif"); + protected final AbstractIcon RELATION_REFERENCE_BACK = createIcon(STRUCTURE_PATH + "referenceBack.gif"); + + public AbstractIcon getIcon(IRelationship.Kind relationship) { + if (relationship == IRelationship.Kind.ADVICE) { + return RELATION_ADVICE_FORWARD; + } else if (relationship == IRelationship.Kind.DECLARE) { + return RELATION_ADVICE_FORWARD; +// } else if (relationship == IRelationship.Kind.INHERITANCE) { +// return RELATION_INHERITANCE_FORWARD; + } else { + return RELATION_REFERENCE_FORWARD; + } + } + + /** + * @return null if the kind could not be resolved + */ + protected abstract AbstractIcon getStructureIcon(IProgramElement.Kind kind, IProgramElement.Accessibility accessibility); + + /** + * Assumes "public" visibility for the icon. + * + * @return null if the kind could not be resolved + */ + public AbstractIcon getIcon(IProgramElement.Kind kind) { + if (kind == IProgramElement.Kind.PROJECT) { + return PROJECT; + } else if (kind == IProgramElement.Kind.PACKAGE) { + return PACKAGE; + } else if (kind == IProgramElement.Kind.FILE) { + return FILE; + } else if (kind == IProgramElement.Kind.FILE_JAVA) { + return FILE_JAVA; + } else if (kind == IProgramElement.Kind.FILE_ASPECTJ) { + return FILE_ASPECTJ; + } else if (kind == IProgramElement.Kind.FILE_LST) { + return FILE_LST; + } else if (kind == IProgramElement.Kind.CLASS) { + return CLASS; + } else if (kind == IProgramElement.Kind.INTERFACE) { + return INTERFACE; + } else if (kind == IProgramElement.Kind.ASPECT) { + return ASPECT; + } else if (kind == IProgramElement.Kind.INITIALIZER) { + return INITIALIZER; + } else if (kind == IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR) { + return INTRODUCTION; + } else if (kind == IProgramElement.Kind.INTER_TYPE_FIELD) { + return INTRODUCTION; + } else if (kind == IProgramElement.Kind.INTER_TYPE_METHOD) { + return INTRODUCTION; + } else if (kind == IProgramElement.Kind.CONSTRUCTOR) { + return CONSTRUCTOR; + } else if (kind == IProgramElement.Kind.METHOD) { + return METHOD; + } else if (kind == IProgramElement.Kind.FIELD) { + return FIELD; + } else if (kind == IProgramElement.Kind.ENUM_VALUE) { + return ENUM_VALUE; + } else if (kind == IProgramElement.Kind.POINTCUT) { + return POINTCUT; + } else if (kind == IProgramElement.Kind.ADVICE) { + return ADVICE; + } else if (kind == IProgramElement.Kind.DECLARE_PARENTS) { + return DECLARE_PARENTS; + } else if (kind == IProgramElement.Kind.DECLARE_WARNING) { + return DECLARE_WARNING; + } else if (kind == IProgramElement.Kind.DECLARE_ERROR) { + return DECLARE_ERROR; + } else if (kind == IProgramElement.Kind.DECLARE_SOFT) { + return DECLARE_SOFT; + } else if (kind == IProgramElement.Kind.DECLARE_PRECEDENCE) { + return DECLARE_SOFT; + } else if (kind == IProgramElement.Kind.CODE) { + return CODE; + } else if (kind == IProgramElement.Kind.ERROR) { + return ERROR; + } else if (kind == IProgramElement.Kind.IMPORT_REFERENCE) { + return RELATION_REFERENCE_FORWARD; + } else if (kind == IProgramElement.Kind.ANNOTATION) { + return ANNOTATION; + } else if (kind == IProgramElement.Kind.ENUM) { + return ENUM; + } else { + System.err.println("AJDE Message: unresolved icon kind " + kind); + return null; + } + } + + /** + * Implement to create platform-specific icons. + */ + protected abstract AbstractIcon createIcon(String path); +} + + + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigEditor.java b/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigEditor.java new file mode 100644 index 000000000..174f92c0c --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigEditor.java @@ -0,0 +1,28 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +import java.io.IOException; + +/** + * @author Mik Kersten + */ +public interface BuildConfigEditor { + + /** + * @param the full path to the file resource to be opened + */ + public void openFile(String filePath) throws IOException, InvalidResourceException; +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigModel.java b/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigModel.java new file mode 100644 index 000000000..717818034 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigModel.java @@ -0,0 +1,145 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.ajde.ui; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + +/** + * TODO: we have schitzophrenia between BuildConfigNode(s) and IProgramElement(s), fix. + * + * @author Mik Kersten + */ +public class BuildConfigModel { + + private BuildConfigNode root = null; + + private String sourceFile; + + public BuildConfigModel(String sourceFile) { + this.sourceFile = sourceFile; + } + + /** + * @param path java.io.File.separator delimited path + * @return corresponding node if the path is found, the root otherwise + */ + public BuildConfigNode getNodeForPath(String path) { + BuildConfigNode upPathMatch = searchUpPaths(path); + if (upPathMatch != null && upPathMatch != root) { + return upPathMatch; + } else { + StringTokenizer st = new StringTokenizer(path, "/"); + return getNodeForPathHelper(st, root); + } + } + + private BuildConfigNode searchUpPaths(String path) { + for (BuildConfigNode node : root.getChildren()) { + if (node.getName().equals(path)) + return node; + } + return null; + } + + private BuildConfigNode getNodeForPathHelper(StringTokenizer st, BuildConfigNode node) { + BuildConfigNode parent = node; + while (st.hasMoreElements()) { + String pathItem = (String) st.nextElement(); + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + node = (BuildConfigNode) it.next(); + String childName = node.getName(); + if (childName.equals(pathItem)) { + return getNodeForPathHelper(st, node); + } + } + } + return parent; + } + + public List<BuildConfigNode> getActiveNodes(BuildConfigNode.Kind kind) { + List<BuildConfigNode> nodes = new ArrayList<BuildConfigNode>(); + getActiveNodesHelper(root, kind, nodes); + return nodes; + } + + private void getActiveNodesHelper(BuildConfigNode node, BuildConfigNode.Kind kind, List<BuildConfigNode> nodes) { + for (BuildConfigNode currNode : node.getChildren()) { + if (currNode.getBuildConfigNodeKind().equals(kind) && currNode.isActive()) { + nodes.add(currNode); + } + getActiveNodesHelper(currNode, kind, nodes); + } + } + + public String getSourceFile() { + return sourceFile; + } + + public void setSourceFile(String sourceFile) { + this.sourceFile = sourceFile; + } + + public BuildConfigNode getRoot() { + return root; + } + + public void setRoot(BuildConfigNode node) { + root = node; + } + + public BuildConfigNode findNodeForSourceLine(String sourceFilePath, int lineNumber) { + BuildConfigNode node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber); + return node; + } + + private BuildConfigNode findNodeForSourceLineHelper(BuildConfigNode node, String sourceFilePath, int lineNumber) { + if (matches(node, sourceFilePath, lineNumber) && !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) { + return node; + } + + if (node != null && node.getChildren() != null) { + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + BuildConfigNode foundNode = findNodeForSourceLineHelper((BuildConfigNode) it.next(), sourceFilePath, lineNumber); + if (foundNode != null) + return foundNode; + } + } + return null; + } + + private boolean matches(BuildConfigNode node, String sourceFilePath, int lineNumber) { + try { + return node != null + && node.getSourceLocation() != null + && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath) + && ((node.getSourceLocation().getLine() <= lineNumber && node.getSourceLocation().getEndLine() >= lineNumber) || (lineNumber <= 1)); + } catch (IOException ioe) { + return false; + } + } + + private boolean hasMoreSpecificChild(BuildConfigNode node, String sourceFilePath, int lineNumber) { + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + BuildConfigNode child = (BuildConfigNode) it.next(); + if (matches(child, sourceFilePath, lineNumber)) + return true; + } + return false; + } + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigNode.java b/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigNode.java new file mode 100644 index 000000000..73e0bead0 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/BuildConfigNode.java @@ -0,0 +1,224 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.ajde.ui; + +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.ISourceLocation; +import org.aspectj.util.FileUtil; + +/** + * @author Mik Kersten + * + * TODO: clean-up after merging of org.aspectj.asm.StructureNode + */ +public class BuildConfigNode { + + protected BuildConfigNode parent = null; + protected String name = ""; + protected Kind kind; + // children.listIterator() should support remove() operation + protected List<BuildConfigNode> children = new ArrayList<BuildConfigNode>(); + protected IMessage message = null; + protected ISourceLocation sourceLocation = null; + + /** + * Used during serialization. + */ + public BuildConfigNode() { + } + + // public BuildConfigNode(String name, String kind, String resourcePath, List children) { + // this(name, kind, children); + // this.resourcePath = resourcePath; + // } + + public BuildConfigNode(String name, Kind kind, String resourcePath) { + this(name, kind); + this.kind = kind; + this.resourcePath = resourcePath; + } + + // public BuildConfigNode(String name, Kind kind, List children) { + // this.name = name; + // this.kind = kind; + // if (children != null) { + // this.children = children; + // } + // setParents(); + // } + + public BuildConfigNode(String name, Kind kind) { + this.name = name; + this.kind = kind; + } + + public String toString() { + return name; + } + + public List<BuildConfigNode> getChildren() { + return children; + } + + public void addChild(BuildConfigNode child) { + if (children == null) { + children = new ArrayList<BuildConfigNode>(); + } + children.add(child); + child.setParent(this); + } + + public void addChild(int position, BuildConfigNode child) { + if (children == null) { + children = new ArrayList<BuildConfigNode>(); + } + children.add(position, child); + child.setParent(this); + } + + public boolean removeChild(BuildConfigNode child) { + child.setParent(null); + return children.remove(child); + } + + /** + * Comparison is string-name based only. + */ + public int compareTo(Object o) throws ClassCastException { + if (o instanceof BuildConfigNode) { + BuildConfigNode sn = (BuildConfigNode) o; + return this.getName().compareTo(sn.getName()); + } + return -1; + } + + public String getName() { + return name; + } + + public ISourceLocation getSourceLocation() { + return sourceLocation; + } + + public void setSourceLocation(ISourceLocation sourceLocation) { + this.sourceLocation = sourceLocation; + } + + public IMessage getMessage() { + return message; + } + + public void setMessage(IMessage message) { + this.message = message; + } + + public BuildConfigNode getParent() { + return parent; + } + + public void setParent(BuildConfigNode parent) { + this.parent = parent; + } + + // private void setParents() { + // if (children == null) return; + // for (Iterator it = children.iterator(); it.hasNext(); ) { + // ((BuildConfigNode)it.next()).setParent(this); + // } + // } + + public void setName(String string) { + name = string; + } + + private String resourcePath; + private boolean isActive = true; + + public String getResourcePath() { + return resourcePath; + } + + public void setResourcePath(String resourcePath) { + this.resourcePath = resourcePath; + } + + public boolean isValidResource() { + return FileUtil.hasSourceSuffix(name) || name.endsWith(".lst"); + } + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean isActive) { + this.isActive = isActive; + } + + /** + * Uses "typesafe enum" pattern. + */ + public static class Kind implements Serializable { + + private static final long serialVersionUID = 3924996793884978885L; + + public static final Kind FILE_JAVA = new Kind("Java source file"); + public static final Kind FILE_ASPECTJ = new Kind("AspectJ source file"); + public static final Kind FILE_LST = new Kind("build configuration file"); + public static final Kind ERROR = new Kind("error"); + public static final Kind DIRECTORY = new Kind("directory"); + + public static final Kind[] ALL = { FILE_JAVA, FILE_ASPECTJ, FILE_LST, DIRECTORY }; + + private final String name; + + private Kind(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // public boolean equals(Object o) { + // return (o instanceof Kind? this==o : false); + // // return o.equals(name); + // } + // + // public int hashCode() { + // return ordinal; + // // return name.hashCode(); + // } + + public boolean isDeclareKind() { + return name.startsWith("declare"); + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } + + public Kind getBuildConfigNodeKind() { + return kind; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/FileStructureView.java b/ajde/src/main/java/org/aspectj/ajde/ui/FileStructureView.java new file mode 100644 index 000000000..6e5107549 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/FileStructureView.java @@ -0,0 +1,48 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + + +/** + * Should only be created by the {@link StructureViewManager} or an + * equivalent factory. + * + * @author Mik Kersten + */ +public class FileStructureView extends StructureView { + + private String sourceFilePath = null; + + public FileStructureView(StructureViewProperties viewProperties) { + super.viewProperties = viewProperties; + } + public String getSourceFile() { + return sourceFilePath; + } + + public void setSourceFile(String sourceFile) { + this.sourceFilePath = sourceFile; + } + + public void setRootNode(IStructureViewNode rootNode) { + super.setRootNode(rootNode); + notifyViewUpdated(); + } + + public String getName() { + return "File view for: " + sourceFilePath; + } +} + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/GlobalStructureView.java b/ajde/src/main/java/org/aspectj/ajde/ui/GlobalStructureView.java new file mode 100644 index 000000000..3abf9c31f --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/GlobalStructureView.java @@ -0,0 +1,52 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + + +/** + * Should only be created by the {@link StructureViewManager} or an + * equivalent factory. + * + * @author Mik Kersten + */ +public class GlobalStructureView extends FileStructureView { + + private GlobalViewProperties viewProperties; + + public GlobalStructureView(GlobalViewProperties viewProperties) { + super(viewProperties); + this.viewProperties = viewProperties; + } + + public GlobalViewProperties getGlobalViewProperties() { + return viewProperties; + } + +// public void setActiveNode(StructureViewNode activeNode) { +// StructureNode node = activeNode.getStructureNode(); +// +// activeNode = activeNode; +// if (renderer != null) renderer.setActiveNode(activeNode); +// } +// +// public void setActiveNode(StructureViewNode activeNode, int sourceLine) { +// activeNode = activeNode; +// if (renderer != null) renderer.setActiveNode(activeNode, sourceLine); +// } + + public String toString() { + return viewProperties.getHierarchy().toString(); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/GlobalViewProperties.java b/ajde/src/main/java/org/aspectj/ajde/ui/GlobalViewProperties.java new file mode 100644 index 000000000..fb58021cc --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/GlobalViewProperties.java @@ -0,0 +1,49 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +/** + * @author Mik Kersten + */ +public class GlobalViewProperties extends StructureViewProperties { + + private StructureViewProperties.Granularity granularity = StructureViewProperties.Granularity.DECLARED_ELEMENTS; + private StructureViewProperties.Hierarchy hierarchy = StructureViewProperties.Hierarchy.DECLARATION; + + public GlobalViewProperties(StructureViewProperties.Hierarchy hierarchy) { + this.hierarchy = hierarchy; + } + + public void setGranularity(StructureViewProperties.Granularity granularity) { + this.granularity = granularity; + } + + public StructureViewProperties.Granularity getGranularity() { + return granularity; + } + + public void setHierarchy(StructureViewProperties.Hierarchy hierarchy) { + this.hierarchy = hierarchy; + } + + public StructureViewProperties.Hierarchy getHierarchy() { + return hierarchy; + } + + public String getName() { + return hierarchy.toString(); + } +} + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/IStructureViewNode.java b/ajde/src/main/java/org/aspectj/ajde/ui/IStructureViewNode.java new file mode 100644 index 000000000..312a4a688 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/IStructureViewNode.java @@ -0,0 +1,83 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +import java.io.*; +import java.util.List; + +import org.aspectj.asm.IProgramElement; + +/** + * @author Mik Kersten + */ +public interface IStructureViewNode { + + public IProgramElement getStructureNode(); + + public AbstractIcon getIcon(); + + /** + * Add a child node. + */ + public void add(IStructureViewNode child); + + /** + * Add a child node. + */ + public void add(IStructureViewNode child, int position); + + /** + * Remove a child node. + */ + public void remove(IStructureViewNode child); + + /** + * @return an empty list if there are no children + */ + public List getChildren(); + + public Kind getKind(); + + public String getRelationshipName(); + + /** + * Uses "typesafe enum" pattern. + */ + public static class Kind implements Serializable { + + private static final long serialVersionUID = 6730849292562214877L; + + public static final Kind DECLARATION = new Kind("declaration"); + public static final Kind RELATIONSHIP = new Kind("relationship"); + public static final Kind LINK = new Kind("link"); + public static final Kind[] ALL = { DECLARATION, RELATIONSHIP, LINK }; + private final String name; + + private Kind(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/InvalidResourceException.java b/ajde/src/main/java/org/aspectj/ajde/ui/InvalidResourceException.java new file mode 100644 index 000000000..a868292a3 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/InvalidResourceException.java @@ -0,0 +1,42 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +/** + * @author Mik Kersten + * + * To change this generated comment edit the template variable "typecomment": + * Window>Preferences>Java>Templates. + */ +public class InvalidResourceException extends Exception { + + private static final long serialVersionUID = -5290919159396792978L; + + /** + * Constructor for InvalidResourceException. + */ + public InvalidResourceException() { + super(); + } + + /** + * Constructor for InvalidResourceException. + * @param s + */ + public InvalidResourceException(String s) { + super(s); + } + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/StructureSearchManager.java b/ajde/src/main/java/org/aspectj/ajde/ui/StructureSearchManager.java new file mode 100644 index 000000000..a8fa324bf --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/StructureSearchManager.java @@ -0,0 +1,64 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + +package org.aspectj.ajde.ui; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.IProgramElement; + +/** + * @author Mik Kersten + */ +public class StructureSearchManager { + + /** + * @param pattern case-sensitive substring of node name + * + * @return null if a corresponding node was not found + */ + public List findMatches(String pattern, IProgramElement.Kind kind) { + + List matches = new ArrayList(); + IHierarchy model = AsmManager.lastActiveStructureModel.getHierarchy(); + if (model.getRoot().equals(IHierarchy.NO_STRUCTURE)) { + return null; + } else { + return findMatchesHelper(model.getRoot(), pattern, kind, matches); + } + } + + private List findMatchesHelper(IProgramElement node, String pattern, IProgramElement.Kind kind, List matches) { + + if (node != null && node.getName().indexOf(pattern) != -1) { + if (kind == null || node.getKind().equals(kind)) { + matches.add(node); + } + } + if (node != null && node.getChildren() != null) { + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + IProgramElement nextNode = (IProgramElement) it.next(); + if (nextNode != null) { + findMatchesHelper(nextNode, pattern, kind, matches); + } + } + } + + return matches; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/StructureView.java b/ajde/src/main/java/org/aspectj/ajde/ui/StructureView.java new file mode 100644 index 000000000..edbae4698 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/StructureView.java @@ -0,0 +1,105 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +import java.util.Iterator; + +import org.aspectj.asm.IProgramElement; + +/** + * @author Mik Kersten + */ +public abstract class StructureView { + + private IStructureViewNode rootNode = null; + private IStructureViewNode activeNode = null; + protected StructureViewProperties viewProperties = null; + protected StructureViewRenderer renderer = null; + + public StructureViewProperties getViewProperties() { + return viewProperties; + } + + public IStructureViewNode getRootNode() { + return rootNode; + } + + public void setRootNode(IStructureViewNode rootNode) { + this.rootNode = rootNode; + } + + public void setViewProperties(StructureViewProperties viewProperties) { + this.viewProperties = viewProperties; + } + + public void setRenderer(StructureViewRenderer renderer) { + this.renderer = renderer; + } + + protected void notifyViewUpdated() { + if (renderer != null) renderer.updateView(this); + } + + /** + * @return the view node corresponding to the active ProgramElementNode or null + */ + public IStructureViewNode getActiveNode() { + if (activeNode != null + && activeNode.getStructureNode()!=null) { + return activeNode; + } else { + return null; + } + } + + /** + * Searches from the root node of the view down in order to find matches. + * + * @return the first match + */ + public IStructureViewNode findCorrespondingViewNode(IProgramElement node) { + return findCorrespondingViewNodeHelper(rootNode, node); + } + + private IStructureViewNode findCorrespondingViewNodeHelper(IStructureViewNode node, IProgramElement pNode) { + if (node != null + && node.getStructureNode() != null + && node.getStructureNode().equals(pNode) + && node.getKind() == IStructureViewNode.Kind.DECLARATION) { + + return node; + } + + if (node != null && node.getChildren() != null) { + for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { + IStructureViewNode foundNode = findCorrespondingViewNodeHelper((IStructureViewNode)it.next(), pNode); + if (foundNode != null) return foundNode; + } + } + + return null; + } + + public void setActiveNode(IStructureViewNode activeNode) { + this.activeNode = activeNode; + if (renderer != null) renderer.setActiveNode(activeNode); + } + + public void setActiveNode(IStructureViewNode activeNode, int sourceLine) { + this.activeNode = activeNode; + if (renderer != null) renderer.setActiveNode(activeNode, sourceLine); + } +} + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewManager.java b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewManager.java new file mode 100644 index 000000000..eb8fdc033 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewManager.java @@ -0,0 +1,231 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + +package org.aspectj.ajde.ui; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.internal.NavigationHistoryModel; +import org.aspectj.ajde.ui.internal.TreeStructureViewBuilder; +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.IHierarchyListener; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.asm.internal.AspectJElementHierarchy; + +/** + * @author Mik Kersten + */ +public class StructureViewManager { + + private final TreeStructureViewBuilder treeViewBuilder; + // private String buildConfigFilePath = null; + + private final NavigationHistoryModel historyModel = new NavigationHistoryModel(); + private final ArrayList structureViews = new ArrayList(); + private FileStructureView defaultFileView = null; + + private static final StructureViewProperties DEFAULT_VIEW_PROPERTIES; + private static final List AVAILABLE_RELATIONS; + + public final IHierarchyListener VIEW_LISTENER = new IHierarchyListener() { + public void elementsUpdated(IHierarchy model) { + // updating structure views: + + for (Iterator it = structureViews.iterator(); it.hasNext();) { + treeViewBuilder.buildView((StructureView) it.next(), (AspectJElementHierarchy) model); + } + } + }; + + /** + * @param nodeFactory concrete factory for creating view nodes + */ + public StructureViewManager(StructureViewNodeFactory nodeFactory) { + treeViewBuilder = new TreeStructureViewBuilder(nodeFactory); + + Ajde.getDefault().getModel().addListener(VIEW_LISTENER); + } + + public void fireNavigateBackAction(StructureView view) { + IProgramElement backNode = historyModel.navigateBack(); + + if (backNode == null) { + Ajde.getDefault().getIdeUIAdapter().displayStatusInformation("No node to navigate back to in history"); + } else { + navigationAction(backNode, false); + } + } + + public void fireNavigateForwardAction(StructureView view) { + IProgramElement forwardNode = historyModel.navigateForward(); + + if (forwardNode == null) { + Ajde.getDefault().getIdeUIAdapter().displayStatusInformation("No node to navigate forward to in history"); + } else { + navigationAction(forwardNode, false); + } + } + + /** + * Only navigations of the default view are registered with the history. + * + * @param newFilePath the canonicalized path to the new file + */ + public void fireNavigationAction(String newFilePath, int lineNumber) { + IProgramElement currNode = Ajde.getDefault().getModel().getHierarchy().findElementForSourceLine(newFilePath, lineNumber); + + if (currNode != null) { + navigationAction(currNode, true); + } + } + + /** + * History is recorded for {@link LinkNode} navigations. + */ + public void fireNavigationAction(IProgramElement pe, boolean isLink) { + navigationAction(pe, isLink); + } + + /** + * Highlights the given node in all structure views. If the node represents code and as such is below the granularity visible in + * the view the parent is highlighted, along with the corresponding sourceline. + */ + private void navigationAction(IProgramElement node, boolean recordHistory) { + if (node == null) + return; + // navigating to node: " + node + ", recordHistory: " + recordHistory + if (recordHistory) + historyModel.navigateToNode(node); + if (defaultFileView != null && node.getSourceLocation() != null) { + String newFilePath = node.getSourceLocation().getSourceFile().getAbsolutePath(); + if (defaultFileView.getSourceFile() != null && !defaultFileView.getSourceFile().equals(newFilePath)) { + defaultFileView.setSourceFile(newFilePath); + treeViewBuilder.buildView(defaultFileView, Ajde.getDefault().getModel().getHierarchy()); + } + } + + for (Iterator it = structureViews.iterator(); it.hasNext();) { + StructureView view = (StructureView) it.next(); + if (!(view instanceof GlobalStructureView) || !recordHistory || defaultFileView == null) { + if (node.getKind().equals(IProgramElement.Kind.CODE)) { + IProgramElement parentNode = node.getParent(); + if (parentNode != null) { + IStructureViewNode currNode = view.findCorrespondingViewNode(parentNode); + int lineOffset = node.getSourceLocation().getLine() - parentNode.getSourceLocation().getLine(); + if (currNode != null) + view.setActiveNode(currNode, lineOffset); + } + } else { + IStructureViewNode currNode = view.findCorrespondingViewNode(node); + if (currNode != null) + view.setActiveNode(currNode); + } + } + } + } + + public void refreshView(StructureView view) { + IStructureViewNode activeNode = view.getActiveNode(); + treeViewBuilder.buildView(view, Ajde.getDefault().getModel().getHierarchy()); + view.setActiveNode(activeNode); + } + + public StructureViewProperties getDefaultViewProperties() { + return DEFAULT_VIEW_PROPERTIES; + } + + /** + * Returns the list of all available relations. + */ + public List getAvailableRelations() { + return AVAILABLE_RELATIONS; + } + + /** + * @param properties can not be null + */ + public GlobalStructureView createGlobalView(GlobalViewProperties properties) { + GlobalStructureView view = new GlobalStructureView(properties); + structureViews.add(view); + return view; + } + + /** + * @param sourceFilePath full path to corresponding source file + * @param properties if null default properties will be used + * @return always returns a view intance + */ + public FileStructureView createViewForSourceFile(String sourceFilePath, StructureViewProperties properties) { + // creating view for file: + if (properties == null) + properties = DEFAULT_VIEW_PROPERTIES; + FileStructureView view = new FileStructureView(properties); + view.setSourceFile(sourceFilePath); + treeViewBuilder.buildView(view, Ajde.getDefault().getModel().getHierarchy()); + structureViews.add(view); + return view; + } + + /** + * @return true if the view was found and removed, false otherwise + */ + public boolean deleteView(StructureView view) { + return structureViews.remove(view); + } + + public void setDefaultFileView(FileStructureView defaultFileView) { + this.defaultFileView = defaultFileView; + } + + public FileStructureView getDefaultFileView() { + return defaultFileView; + } + + static { + AVAILABLE_RELATIONS = new ArrayList(); + AVAILABLE_RELATIONS.add(IRelationship.Kind.ADVICE); + AVAILABLE_RELATIONS.add(IRelationship.Kind.DECLARE); + + DEFAULT_VIEW_PROPERTIES = new StructureViewProperties(); + DEFAULT_VIEW_PROPERTIES.setRelations(AVAILABLE_RELATIONS); + } + +} + +// this.multiFileViewMode = multiFileViewMode; +// if (!multiFileViewMode) { +// structureViews.add(DEFAULT_FILE_VIEW); +// structureViews.add(DECLARATION_VIEW); +// structureViews.add(CROSSCUTTING_VIEW); +// structureViews.add(INHERITANCE_VIEW); +// } + +// public GlobalStructureView getGlobalStructureView(StructureViewProperties.Hierarchy hierarchy) { +// if (hierarchy == StructureViewProperties.Hierarchy.CROSSCUTTING) { +// return CROSSCUTTING_VIEW; +// } else if (hierarchy == StructureViewProperties.Hierarchy.INHERITANCE) { +// return INHERITANCE_VIEW; +// } else { +// return DECLARATION_VIEW; +// } +// } + +// public FileStructureView getDefaultFileStructureView() { +// return DEFAULT_FILE_VIEW; +// } + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewNodeFactory.java b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewNodeFactory.java new file mode 100644 index 000000000..cb82a65db --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewNodeFactory.java @@ -0,0 +1,102 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + +package org.aspectj.ajde.ui; + +import java.util.Iterator; +import java.util.List; + +import org.aspectj.ajde.Ajde; +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.asm.IRelationshipMap; + +/** + * @author Mik Kersten + */ +public abstract class StructureViewNodeFactory { + + private final AbstractIconRegistry iconRegistry; + + public StructureViewNodeFactory(AbstractIconRegistry iconRegistry) { + this.iconRegistry = iconRegistry; + } + + public IStructureViewNode createNode(IProgramElement node) { + return createNode(node, null); + } + + public IStructureViewNode createNode(IProgramElement node, List children) { + AbstractIcon icon = iconRegistry.getStructureIcon(node.getKind(), node.getAccessibility()); + + IStructureViewNode svNode = createDeclaration(node, icon, children); + String nodeHandle = node.getHandleIdentifier(); + // Don't put relationships on fields as they can then appear twice when building the outline - + // once under clinit field-set nodes and once under the field declaration. + if (nodeHandle != null && !node.getKind().equals(IProgramElement.Kind.FIELD)) { + AsmManager manager = Ajde.getDefault().getModel(); + IRelationshipMap relMap = (manager == null ? null : manager.getRelationshipMap()); + List relationships = (relMap == null ? null : relMap.get(nodeHandle)); + if (relationships != null) { + for (Iterator it = relationships.iterator(); it.hasNext();) { + IRelationship rel = (IRelationship) it.next(); + if (rel != null && rel.getTargets().size() > 0) { + IStructureViewNode relNode = createRelationship(rel, iconRegistry.getIcon(rel.getKind())); + if (relNode != null) { + svNode.add(relNode, 0); + for (Iterator it2 = rel.getTargets().iterator(); it2.hasNext();) { + String handle = (String) it2.next(); + IProgramElement link = Ajde.getDefault().getModel().getHierarchy().findElementForHandle(handle); + if (link != null) { + IStructureViewNode linkNode = createLink(link, iconRegistry.getStructureIcon(link.getKind(), + link.getAccessibility())); + relNode.add(linkNode); + } + } + } + } + } + } + } + return svNode; + } + + /** + * Implementors must override this method in order to create link new nodes. + */ + protected abstract IStructureViewNode createLink(IProgramElement node, AbstractIcon icon); + + /** + * Implementors must override this method in order to create new relationship nodes. + * + * If returned node is null it will not be added to the tree. + */ + protected abstract IStructureViewNode createRelationship(IRelationship relationship, AbstractIcon icon); + + /** + * Implementors must override this method in order to create new nodes. + */ + protected abstract IStructureViewNode createDeclaration(IProgramElement node, AbstractIcon icon, List children); + + /** + * Don't show code elements under types since they show under the corresponding initializers. + */ + public static boolean acceptNode(IProgramElement parent, IProgramElement child) { + if (parent.getKind() == IProgramElement.Kind.CLASS && child.getKind() == IProgramElement.Kind.CODE) { + return false; + } else { + return true; + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewProperties.java b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewProperties.java new file mode 100644 index 000000000..5351803d4 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewProperties.java @@ -0,0 +1,257 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +import java.io.ObjectStreamException; +import java.util.*; + +import org.aspectj.asm.*; + +/** + * Nested properties use the typesafe enum pattern. + * + * @author Mik Kersten + */ +public class StructureViewProperties { + + /** + * @deprecated + */ + public static final String SORT_DECLARATIONAL = StructureViewProperties.Sorting.DECLARATIONAL.toString(); + + /** + * @deprecated + */ + public void setSorting(String sorting) { } + + private List relations = new ArrayList(); + private List filteredMemberAccessibility = new ArrayList(); + private List filteredMemberModifiers = new ArrayList(); + private List filteredMemberKinds = new ArrayList(); + private List grouping = new ArrayList(); + private Sorting sorting = Sorting.DECLARATIONAL; + private Granularity granularity = StructureViewProperties.Granularity.DECLARED_ELEMENTS; + + public List getRelations() { + return relations; + } + + public void setRelations(List relations) { + this.relations = relations; + } + + public void addRelation(IRelationship.Kind kind) { + relations.add(kind); + } + + public void removeRelation(IRelationship.Kind kind) { + relations.remove(kind); + } + + public void setFilteredMemberAccessibility(List memberVisibility) { + this.filteredMemberAccessibility = memberVisibility; + } + + public List getFilteredMemberAccessibility() { + return filteredMemberAccessibility; + } + + public void addFilteredMemberAccessibility(IProgramElement.Accessibility accessibility) { + this.filteredMemberAccessibility.add(accessibility); + } + + public void removeFilteredMemberAccessibility(IProgramElement.Accessibility accessibility) { + this.filteredMemberAccessibility.remove(accessibility); + } + + public List getFilteredMemberModifiers() { + return filteredMemberModifiers; + } + + public void setFilteredMemberModifiers(List memberModifiers) { + this.filteredMemberModifiers = memberModifiers; + } + + public void addFilteredMemberModifiers(IProgramElement.Modifiers modifiers) { + this.filteredMemberModifiers.add(modifiers); + } + + public void removeFilteredMemberModifiers(IProgramElement.Modifiers modifiers) { + this.filteredMemberModifiers.remove(modifiers); + } + + public StructureViewProperties.Sorting getSorting() { + return sorting; + } + + public void setSorting(StructureViewProperties.Sorting sorting) { + this.sorting = sorting; + } + + public List getFilteredMemberKinds() { + return filteredMemberKinds; + } + + public void setFilteredMemberKinds(List memberKinds) { + this.filteredMemberKinds = memberKinds; + } + + public void addFilteredMemberKind(IProgramElement.Kind kind) { + this.filteredMemberKinds.add(kind); + } + + public void removeFilteredMemberKind(IProgramElement.Kind kind) { + this.filteredMemberKinds.remove(kind); + } + + public List getGrouping() { + return grouping; + } + + public void setGrouping(List grouping) { + this.grouping = grouping; + } + + + public void addGrouping(Grouping grouping) { + this.grouping.add(grouping); + } + + public void removeGrouping(Grouping grouping) { + this.grouping.remove(grouping); + } + + public Granularity getGranularity() { + return granularity; + } + + public void setGranularity(Granularity granularity) { + this.granularity = granularity; + } + + public String getName() { + return "<unnamed view>"; + } + + public String toString() { + return "\nView Properties:" + + "\n-> sorting: " + sorting + + "\n-> grouping: " + grouping + + "\n-> filtered member kinds: " + filteredMemberKinds + + "\n-> filtered member accessibility: " + filteredMemberAccessibility + + "\n-> filtered member modifiers: " + filteredMemberModifiers + + "\n-> relations: " + relations; + } + + public static class Hierarchy { + + public static final Hierarchy DECLARATION = new Hierarchy("package hierarchy"); + public static final Hierarchy CROSSCUTTING = new Hierarchy("crosscutting structure"); + public static final Hierarchy INHERITANCE = new Hierarchy("type hierarchy"); + public static final Hierarchy[] ALL = { DECLARATION, CROSSCUTTING, INHERITANCE }; + + private final String name; + + private Hierarchy(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } + + public static class Grouping { + + public static final Grouping KIND = new Grouping("group by kind"); + public static final Grouping VISIBILITY = new Grouping("group by visibility"); + public static final Grouping[] ALL = { KIND, VISIBILITY }; + + private final String name; + + private Grouping(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } + + public static class Sorting { + + public static final Sorting ALPHABETICAL = new Sorting("sort alphabetically"); + public static final Sorting DECLARATIONAL = new Sorting("sort declarationally"); + public static final Sorting[] ALL = { ALPHABETICAL, DECLARATIONAL }; + + private final String name; + + private Sorting(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } + + public static class Granularity { + + public static final Granularity PACKAGE = new Granularity("package"); + public static final Granularity FILE = new Granularity("file"); + public static final Granularity TYPE = new Granularity("type"); + public static final Granularity MEMBER = new Granularity("member"); + public static final Granularity DECLARED_ELEMENTS = new Granularity("declared body elements"); + public static final Granularity[] ALL = { PACKAGE, FILE, TYPE, MEMBER, DECLARED_ELEMENTS }; + + private final String name; + + private Granularity(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + // The 4 declarations below are necessary for serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private Object readResolve() throws ObjectStreamException { + return ALL[ordinal]; + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewRenderer.java b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewRenderer.java new file mode 100644 index 000000000..c31a130fa --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/StructureViewRenderer.java @@ -0,0 +1,49 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui; + +import java.util.EventListener; + +/** + * View renderers get notified of structure view update events and should + * update the display of the structure view accordingly. + * + * @author Mik Kersten + */ +public interface StructureViewRenderer extends EventListener { + + /** + * Implementors should updated the display of the corresponding + * file structure view. + */ + public void updateView(StructureView structureView); + + /** + * Highlights and selects the given node as active. What "active" + * means depends on the renderer: a typical activation should cause + * the corresponding node's sourceline to be highlighted in the + * active editor. + */ + public void setActiveNode(IStructureViewNode node); + + /** + * Same behavior as <CODE>setActiveNode(StructureViewNode)</CODE> but + * highlights a particular line within the span of the node. + * + * @param lineOffset number of lines after the begin and before the + * end line of the corresponding <CODE>StructureNode</CODE>. + */ + public void setActiveNode(IStructureViewNode activeNode, int lineOffset); +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/UserPreferencesAdapter.java b/ajde/src/main/java/org/aspectj/ajde/ui/UserPreferencesAdapter.java new file mode 100644 index 000000000..5d8560952 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/UserPreferencesAdapter.java @@ -0,0 +1,67 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + + +package org.aspectj.ajde.ui; + +import java.util.List; + +/** + * This interface needs to be implemented by an IDE extension in order for AJDE + * to store properties in a way that matches the IDE's property storing facilities. + * + * @author Mik Kersten + */ +public interface UserPreferencesAdapter { + + /** + * Retrieves a global IDE option. + */ + public String getGlobalPreference(String name); + + /** + * Retrieves a global IDE option. + */ + public List getGlobalMultivalPreference(String name); + + /** + * Sets a global IDE option with a single value. + */ + public void setGlobalPreference(String name, String value); + + /** + * Sets a global IDE option with multiple values. + */ + public void setGlobalMultivalPreference(String name, List values); + + /** + * Retrieves an option for the currently active project. + */ + public String getProjectPreference(String name); + + /** + * Retrieves an option for the currently active project. + */ + public List getProjectMultivalPreference(String name); + + /** + * Sets an option for the currently active project. + */ + public void setProjectPreference(String name, String value); + + /** + * Sets an option for the currently active project. + */ + public void setProjectMultivalPreference(String name, List values); +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/internal/NavigationHistoryModel.java b/ajde/src/main/java/org/aspectj/ajde/ui/internal/NavigationHistoryModel.java new file mode 100644 index 000000000..0aad967fb --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/internal/NavigationHistoryModel.java @@ -0,0 +1,57 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.internal; + +import java.util.Stack; + +import org.aspectj.asm.IProgramElement; + +/** + * @author Mik Kersten + */ +public class NavigationHistoryModel { + + private IProgramElement currNode = null; + private Stack backHistory = new Stack(); + private Stack forwardHistory = new Stack(); + + /** + * @return null if the history is empty + */ + public IProgramElement navigateBack() { + if (backHistory.isEmpty() || currNode == null) return null; + + forwardHistory.push(currNode); + currNode = (IProgramElement)backHistory.pop(); + return currNode; + } + + /** + * @return null if the history is empty + */ + public IProgramElement navigateForward() { + if (forwardHistory.isEmpty() || currNode == null) return null; + + backHistory.push(currNode); + currNode = (IProgramElement)forwardHistory.pop(); + return currNode; + } + + + public void navigateToNode(IProgramElement toNode) { + if (currNode != null) backHistory.push(currNode); + currNode = toNode; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java b/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java new file mode 100644 index 000000000..af1a2477f --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java @@ -0,0 +1,460 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.internal; + +import java.util.*; + +import org.aspectj.ajde.ui.*; +import org.aspectj.asm.*; +//import org.aspectj.asm.internal.*; +//import org.aspectj.asm.internal.ProgramElement; + +/** + * @author Mik Kersten + */ +public class TreeStructureViewBuilder { + + private StructureViewNodeFactory nodeFactory; + + public TreeStructureViewBuilder(StructureViewNodeFactory nodeFactory) { + this.nodeFactory = nodeFactory; + } + + /** + * @todo get rid of instanceof tests + */ + public void buildView(StructureView view, IHierarchy model) { +// StructureViewProperties properties = view.getViewProperties(); + IProgramElement modelRoot = null; +// boolean noStructure = false; + if (isFileView(view)) { + FileStructureView fileView = (FileStructureView)view; + if (fileView.getSourceFile() == null) { + modelRoot = IHierarchy.NO_STRUCTURE; +// noStructure = true; + } else { + modelRoot = model.findElementForSourceFile(fileView.getSourceFile()); + } + } else { + modelRoot = model.getRoot(); + } + + IStructureViewNode viewRoot = null; + if (!isFileView(view)) { + StructureViewProperties.Hierarchy hierarchy + = ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy(); + if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING) + || hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { + viewRoot = buildCustomTree((GlobalStructureView)view, model); + } + } + if (viewRoot == null) { + viewRoot = createViewNode(modelRoot, view.getViewProperties());//modelRoot; + } + + if (view.getViewProperties().getSorting() == StructureViewProperties.Sorting.ALPHABETICAL + || (!isFileView(view) && + ((GlobalStructureView)view).getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.DECLARATION))) { + sortView(viewRoot, ALPHABETICAL_COMPARATOR); + } else { + sortView(viewRoot, DECLARATIONAL_COMPARATOR); + } + + addPackageNode(view, viewRoot); + view.setRootNode(viewRoot); + } + + private void addPackageNode(StructureView view, IStructureViewNode viewRoot) { + if (isFileView(view)) { +// IProgramElement fileNode = viewRoot.getStructureNode(); +// IProgramElement parentNode = fileNode.getParent(); +// +// if (parentNode.getKind() == IProgramElement.Kind.PACKAGE) { +// String name = parentNode.getName(); +// IProgramElement packageNode = new ProgramElement(name, IProgramElement.Kind.PACKAGE, null); +// packageNode.setSourceLocation(fileNode.getSourceLocation()); +// StructureViewNode packageViewNode = createViewNode( +// packageNode, +// view.getViewProperties() +// ); +// viewRoot.getChildren().add(0, packageViewNode); +// }; + } + } + + private IStructureViewNode createViewNode(IProgramElement node, StructureViewProperties properties) { + if (node == null) return null; + List children = new ArrayList(); +// IProgramElement pNode = node; +// if (node.getRelations() != null) { +// for (Iterator it = node.getRelations().iterator(); it.hasNext(); ) { +// IProgramElement IProgramElement = (IProgramElement)it.next(); +// if (acceptNode(IProgramElement, properties)) { +// children.add(createViewNode(IProgramElement, properties)); +// } +// } +// } + if (node.isRunnable() && node.getParent() != null) { + IProgramElement parent = node.getParent(); + if (parent.getKind().equals(IProgramElement.Kind.CLASS) + || parent.getKind().equals(IProgramElement.Kind.ASPECT)) { + parent.setRunnable(true); + node.setRunnable(false); + } + } + if (node.getChildren() != null) { + for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { + IProgramElement IProgramElement = (IProgramElement)it.next(); + if (acceptNode(IProgramElement, properties)) { + children.add(createViewNode(IProgramElement, properties)); + } + } + } + + IStructureViewNode viewNode = nodeFactory.createNode(node, children);//new TreeViewNode(root, null, children); + return viewNode; + } + + /** + * @todo get rid of this test, fix polymorphism + */ + private boolean isFileView(StructureView view) { + return view instanceof FileStructureView + && !(view instanceof GlobalStructureView); + } + + private boolean acceptGranularity(IProgramElement.Kind kind, StructureViewProperties.Granularity granularity) { + + if (granularity == StructureViewProperties.Granularity.DECLARED_ELEMENTS) { + return true; + } else if (granularity == StructureViewProperties.Granularity.MEMBER && + (kind != IProgramElement.Kind.CODE)) { + return true; + } else if (granularity == StructureViewProperties.Granularity.TYPE + && (kind == IProgramElement.Kind.PROJECT + || kind == IProgramElement.Kind.PACKAGE + || kind.isSourceFile() + || kind.isType())) { + return true; + } else if (granularity == StructureViewProperties.Granularity.FILE + && (kind == IProgramElement.Kind.PROJECT + || kind == IProgramElement.Kind.PACKAGE + || kind.isSourceFile())) { + return true; + } else if (granularity == StructureViewProperties.Granularity.PACKAGE + && (kind == IProgramElement.Kind.PROJECT + || kind == IProgramElement.Kind.PACKAGE)) { + return true; + } else { + return false; + } + } + + private boolean acceptNode(IProgramElement node, StructureViewProperties properties) { + if (node!=null) { + IProgramElement pNode = node; + if (!acceptGranularity(pNode.getKind(), properties.getGranularity())) { + return false; + } else if (pNode.getKind().isMember()) { + if (properties.getFilteredMemberAccessibility().contains(pNode.getAccessibility())) { + return false; + } + if (properties.getFilteredMemberKinds().contains(pNode.getKind())) { + return false; + } + for (Iterator it = pNode.getModifiers().iterator(); it.hasNext(); ) { + if (properties.getFilteredMemberModifiers().contains(it.next())) { + return false; + } + } + } + } + return true; + } + + private void sortView(IStructureViewNode node, Comparator comparator) { + if (node == null || node.getChildren() == null) return; + Collections.sort(node.getChildren(), comparator); + for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { + IStructureViewNode nextNode = (IStructureViewNode)it.next(); + if (nextNode != null) sortView(nextNode, comparator); + } + } + + private IStructureViewNode buildCustomTree(GlobalStructureView view, IHierarchy model) { + IProgramElement rootNode = model.getRoot(); + IStructureViewNode treeNode = nodeFactory.createNode(rootNode); + + List rootNodes = new ArrayList(); + getRoots(rootNode, rootNodes, view.getGlobalViewProperties().getHierarchy()); + + for (Iterator it = rootNodes.iterator(); it.hasNext(); ) { + if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { + treeNode.add(getCrosscuttingChildren((IProgramElement)it.next())); + } else if (view.getGlobalViewProperties().getHierarchy().equals(StructureViewProperties.Hierarchy.INHERITANCE)) { + treeNode.add(getInheritanceChildren( + (IProgramElement)it.next(), + view.getViewProperties().getRelations()) + ); + } + } + return treeNode; + } + + private void getRoots(IProgramElement rootNode, List roots, StructureViewProperties.Hierarchy hierarchy) { +// if (rootNode != null && rootNode.getChildren() != null) { +// for (Iterator it = rootNode.getChildren().iterator(); it.hasNext(); ) { +// IProgramElement node = (IProgramElement)it.next(); +// if (node instanceof IProgramElement) { +// if (acceptNodeAsRoot((IProgramElement)node, hierarchy)) { +// IProgramElement pNode = (IProgramElement)node; +// List relations = pNode.getRelations(); +// String delimiter = ""; +// if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { +// delimiter = "uses pointcut"; +// } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { +// delimiter = "inherits"; +// } +// if (relations != null && relations.toString().indexOf(delimiter) == -1) { +// boolean found = false; +// for (Iterator it2 = roots.iterator(); it2.hasNext(); ) { +// if (((IProgramElement)it2.next()).equals(pNode)) found = true; +// } +// if (!found) roots.add(pNode); +// } +// } +// } +// getRoots(node, roots, hierarchy); +// } +// } + } + + public boolean acceptNodeAsRoot(IProgramElement node, StructureViewProperties.Hierarchy hierarchy) { + if (hierarchy.equals(StructureViewProperties.Hierarchy.CROSSCUTTING)) { + return node.getKind().equals(IProgramElement.Kind.ADVICE) + || node.getKind().equals(IProgramElement.Kind.POINTCUT); + } else if (hierarchy.equals(StructureViewProperties.Hierarchy.INHERITANCE)) { + return node.getKind().equals(IProgramElement.Kind.CLASS); + } else { + return false; + } + } + + private IStructureViewNode getInheritanceChildren(IProgramElement node, List associations) { +// IStructureViewNode treeNode = nodeFactory.createNode(node); +// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); +// List relations = ((IProgramElement)node).getRelations(); + throw new RuntimeException("unimplemented"); +// if (relations != null) { +// for (Iterator it = relations.iterator(); it.hasNext(); ) { +// IRelationship relation = (IRelationship)it.next(); +// if (relation.getName().equals("is inherited by")) { +// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { +//// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); +//// StructureViewNode newNode = getInheritanceChildren(pNode, associations); +// StructureViewNode typeChildren = buildTree(newNode.getStructureNode(), associations); +// for (int i = 0; i < typeChildren.getChildren().size(); i++) { +// newNode.add((StructureViewNode)typeChildren.getChildren().get(i)); +// } +// treeNode.add(newNode); +// } +// } +// } +// } +// return treeNode; + } + + private IStructureViewNode getCrosscuttingChildren(IProgramElement node) { + //StructureViewNodeAdapter treeNode = new StructureViewNodeAdapter(node); +// IStructureViewNode treeNode = nodeFactory.createNode(node); +// List relations = ((IProgramElement)node).getRelations(); + throw new RuntimeException("unimplemented"); +// if (relations != null) { +// for (Iterator it = relations.iterator(); it.hasNext(); ) { +// IRelationship relation = (IRelationship)it.next(); +// if (relation.getName().equals("pointcut used by")) { +// for (Iterator it2 = relation.getTargets().iterator(); it2.hasNext(); ) { +// IProgramElement pNode = ((LinkNode)it2.next()).getProgramElementNode(); +// StructureViewNode newNode = getCrosscuttingChildren(pNode); +// for (Iterator it3 = pNode.getRelations().iterator(); it3.hasNext(); ) { +// IRelationship relationNode = (IRelation)it3.next(); +// if (relationNode.getName().indexOf("pointcut") == -1) { +// newNode.add(getRelations(relationNode)); +// } +// } +// treeNode.add(newNode); +// } +// } else if (relations.toString().indexOf("uses pointcut") == -1) { +// for (Iterator it4 = relations.iterator(); it4.hasNext(); ) { +// IRelation relationNode = (IRelationship)it4.next(); +// if (relationNode.getName().indexOf("pointcut") == -1) { +// treeNode.add(getRelations(relationNode)); +// } +// } +// } +// } +// } +// return treeNode; + } + +// private IStructureViewNode buildTree(IProgramElement node, List associations) { +// //StructureViewNode treeNode = new StructureViewNodeAdapter(node); +// IStructureViewNode treeNode = nodeFactory.createNode(node); +//// if (node instanceof IProgramElement) { +// List relations = ((IProgramElement)node).getRelations(); +// if (relations != null) { +// for (Iterator it = relations.iterator(); it.hasNext(); ) { +// IRelationship relationNode = (IRelationship)it.next(); +// if (associations.contains(relationNode.toString())) { +// treeNode.add(buildTree(relationNode, associations)); +// } +// } +// } +// } +// if (node != null) { +// List children = null; +// children = node.getChildren(); +// if (children != null) { +// List childList = new ArrayList(); +// for (Iterator itt = children.iterator(); itt.hasNext(); ) { +// IProgramElement child = (IProgramElement)itt.next(); +// if (child instanceof IProgramElement) { +// IProgramElement progNode = (IProgramElement)child; +//// if (progNode.getKind() != IProgramElement.Kind.CODE) { +// childList.add(buildTree(child, associations)); +//// } +// } else { +// childList.add(buildTree(child, associations)); +// } +// } +// //sortNodes(childList); +// for (Iterator it = childList.iterator(); it.hasNext(); ) { +// treeNode.add((IStructureViewNode)it.next()); +// } +// } +// +// } +// return treeNode; +// } + +// private IStructureViewNode getRelations(IRelationship node) { +// return null; +// //StructureViewNode treeNode = new StructureViewNode(node); +//// IStructureViewNode treeNode = nodeFactory.c(node); +//// for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { +//// treeNode.add( +//// nodeFactory.createNode((IProgramElement)it.next()) +//// ); +//// } +//// return treeNode; +// } +// +// /** +// * For debugging only. +// */ +// private void dumpView(IStructureViewNode root, int level) { +// System.out.println(root.getStructureNode()); +// for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) { +// dumpView((IStructureViewNode)it.next(), level++); +// } +// for (int i = 0; i < level; i++) { +// System.out.print(' '); +// } +// } + + /** + * Does not sort imports alphabetically. + */ + private static final Comparator ALPHABETICAL_COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); + IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); + + if (sv1!=null && sv2!=null) { + + if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; + if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; + + return sv1.getName().compareTo(sv2.getName()); + } else { + return 0; + } + } + }; + + private static final Comparator DECLARATIONAL_COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + IProgramElement sv1 = ((IStructureViewNode)o1).getStructureNode(); + IProgramElement sv2 = ((IStructureViewNode)o2).getStructureNode(); + if (sv1!=null && sv2!=null) { + if (sv2.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return 1; + if (sv1.getKind() == IProgramElement.Kind.IMPORT_REFERENCE) return -1; + if (sv1.getSourceLocation() == null || sv2.getSourceLocation() == null) { + return 0; + } else if (sv1.getSourceLocation().getLine() < sv2.getSourceLocation().getLine()) { + return -1; + } else { + return 1; + } + } else { + return 0; + } + } + }; +} + +// private boolean acceptNode(ProgramElementNode node) { +// return true; +// if (node.getKind().equals("package")) return true; +// +// if (node.getKind().equals("file")) { +// if (granularity == ViewProperties.Granularity.PACKAGE) { +// return false; +// } else { +// return true; +// } +// } +// +// if (node.getKind().equals("class") || node.getKind().equals("aspect") || node.getKind().equals("interface")) { +// if (granularity == ViewProperties.Granularity.FILE || granularity == ViewProperties.Granularity.PACKAGE) { +// return false; +// } else { +// return true; +// } +// } +// +// if (node.isMemberKind()) { +// if (granularity == ViewProperties.Granularity.MEMBER) { +// for (Iterator it = modifiers.iterator(); it.hasNext(); ) { +// if (node.getModifiers().contains((String)it.next())) return false; +// } +// for (Iterator it2 = visibility.iterator(); it2.hasNext(); ) { +// if (node.getAccessibility().equals((String)it2.next())) return false; +// } +// if (filteredMemberKinds.contains(node.getKind())) { +// return false; +// } else { +// return true; +// } +// } else { +// return false; +// } +// } +// +// if (node.isCode()) return false; +// +// return false; +// } + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java b/ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java new file mode 100644 index 000000000..b1120f0fb --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/internal/UserPreferencesStore.java @@ -0,0 +1,153 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + + +package org.aspectj.ajde.ui.internal; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.UserPreferencesAdapter; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; +import org.aspectj.util.LangUtil; + +public class UserPreferencesStore implements UserPreferencesAdapter { + public static final String FILE_NAME = "/.ajbrowser"; + private static final String VALUE_SEP = ";"; + private Properties properties = new Properties(); + private boolean persist = true; + + public UserPreferencesStore() { + this(true); + } + + public UserPreferencesStore(boolean loadDefault) { + persist = loadDefault; + if (persist) { + loadProperties(getPropertiesFilePath()); + } + } + + public String getProjectPreference(String name) { + return properties.getProperty(name); + } + + public List getProjectMultivalPreference(String name) { + List values = new ArrayList(); + String valuesString = properties.getProperty(name); + if (valuesString != null && !valuesString.trim().equals("")) { + StringTokenizer st = new StringTokenizer(valuesString, VALUE_SEP); + while (st.hasMoreTokens()) { + values.add(st.nextToken()); + } + } + return values; + } + + public void setProjectPreference(String name, String value) { + properties.setProperty(name, value); + saveProperties(); + } + + public void setProjectMultivalPreference(String name, List values) { + String valuesString = ""; + for (Iterator it = values.iterator(); it.hasNext(); ) { + valuesString += (String)it.next() + ';'; + } + properties.setProperty(name, valuesString); + saveProperties(); + } + + public static String getPropertiesFilePath() { + String path = System.getProperty("user.home"); + if (path == null) { + path = "."; + } + return path + FILE_NAME; + } + + public String getGlobalPreference(String name) { + return getProjectPreference(name); + } + + public List getGlobalMultivalPreference(String name) { + return getProjectMultivalPreference(name); + } + + public void setGlobalPreference(String name, String value) { + setProjectPreference(name, value); + } + + public void setGlobalMultivalPreference(String name, List values) { + setProjectMultivalPreference(name, values); + } + private void loadProperties(String path) { + if (LangUtil.isEmpty(path)) { + return; + } + File file = new File(path); + if (!file.canRead()) { + return; + } + FileInputStream in = null; + try { + path = getPropertiesFilePath(); + in = new FileInputStream(file); + properties.load(in); + } catch (IOException ioe) { + Message msg = new Message("Error reading properties from " + path,IMessage.ERROR,ioe,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } finally { + if (null != in) { + try { + in.close(); + } catch (IOException e) { + // ignore + } + } + } + } + public void saveProperties() { + if (!persist) return; + + FileOutputStream out = null; + String path = null; + try { + path = getPropertiesFilePath(); + out = new FileOutputStream(path); + properties.store(out, "AJDE Settings"); + } catch (IOException ioe) { + Message msg = new Message("Error writing properties to " + path,IMessage.ERROR,ioe,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } finally { + if (null != out) { + try { + out.close(); + } catch (IOException e) { + // ignore + } + } + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaBuildOptions.java b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaBuildOptions.java new file mode 100644 index 000000000..0fd719f85 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaBuildOptions.java @@ -0,0 +1,168 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.util.Map; + +import org.aspectj.ajde.core.JavaOptions; + +/** + * Class which handles the setting of the java options and the java options map required by + * ICompilerConfiguration#getJavaOptionsMap() + */ +public class JavaBuildOptions { + + private Map<String, String> javaBuildOptions; + + public JavaBuildOptions() { + javaBuildOptions = JavaOptions.getDefaultJavaOptions(); + } + + public Map<String, String> getJavaBuildOptionsMap() { + return javaBuildOptions; + } + + public void setOption(String javaOption, String value) { + javaBuildOptions.put(javaOption, value); + } + + // ----------------- compliance settings --------------- + + // compliance + public void setComplianceLevel(String level) { + if (JavaOptions.isValidJvmVersion(level)) { + javaBuildOptions.put(JavaOptions.COMPLIANCE_LEVEL, level); + } + } + + // source + public void setSourceCompatibilityLevel(String level) { + if (JavaOptions.isValidJvmVersion(level)) { + javaBuildOptions.put(JavaOptions.SOURCE_COMPATIBILITY_LEVEL, level); + } + } + + // target + public void setTargetLevel(String level) { + if (JavaOptions.isValidJvmVersion(level)) { + javaBuildOptions.put(JavaOptions.TARGET_COMPATIBILITY_LEVEL, level); + } + } + + // ---------------- compiler warning options ------------------ + + // warn method with constructor name + public void setWarnMethodWithConstructorName(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME, option); + } + } + + // warn overriding package default method + public void setWarnOverridingPackageDefaultMethod(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD, option); + } + } + + // warn deprecation + public void setWarnDeprecation(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_DEPRECATION, option); + } + } + + // warn hidden catch blocks + public void setWarnHiddenCatchBlocks(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_HIDDEN_CATCH_BLOCKS, option); + } + } + + // warn unused locals + public void setWarnUnusedLocals(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_UNUSED_LOCALS, option); + } + } + + // warn unused parameters + public void setWarnUnusedParameters(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_UNUSED_PARAMETER, option); + } + } + + // warn unused imports + public void setWarnUnusedImports(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_UNUSED_IMPORTS, option); + } + } + + // warn synthetic access + public void setWarnSyntheticAccess(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_SYNTHETIC_ACCESS, option); + } + } + + // warn assert identifier + public void setWarnAssertIdentifier(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_ASSERT_IDENITIFIER, option); + } + } + + // warn non nls + public void setWarnNonNLS(String option) { + if (JavaOptions.isIgnoreOrWarning(option)) { + javaBuildOptions.put(JavaOptions.WARN_NON_NLS, option); + } + } + + // --------------- debug options -------------------- + + // debug source + public void setDebugSource(String option) { + if (JavaOptions.isGenerateOrNot(option)) { + javaBuildOptions.put(JavaOptions.DEBUG_SOURCE, option); + } + } + + // debug lines + public void setDebugLines(String option) { + if (JavaOptions.isGenerateOrNot(option)) { + javaBuildOptions.put(JavaOptions.DEBUG_LINES, option); + } + } + + // debug vars + public void setDebugVariables(String option) { + if (JavaOptions.isGenerateOrNot(option)) { + javaBuildOptions.put(JavaOptions.DEBUG_VARS, option); + } + } + + // preserve all locals + public void setPreserveAllLocals(String value) { + if (JavaOptions.isValidPreserveAllLocalsOption(value)) { + javaBuildOptions.put(JavaOptions.PRESERVE_ALL_LOCALS, value); + } + } + + // ----------- other settings + // character encoding + public void setCharacterEncoding(String value) { + javaBuildOptions.put(JavaOptions.CHARACTER_ENCODING, value); + } + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaCompilerWarningsOptionsPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaCompilerWarningsOptionsPanel.java new file mode 100644 index 000000000..f34ace5df --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaCompilerWarningsOptionsPanel.java @@ -0,0 +1,140 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the java compiler warning options. + * Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaCompilerWarningsOptionsPanel extends OptionsPanel { + + private final String[] ignoreOrWarning = new String[] {JavaOptions.IGNORE,JavaOptions.WARNING}; + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border warningsEtchedBorder; + private TitledBorder warningsTitleBorder; + private Border warningsCompoundBorder; + private JPanel warningsPanel; + private Box warningsBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private Map/*String --> JComboBox*/ warningComboBoxes = new HashMap(); + + public JavaCompilerWarningsOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Compiler Warning Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createWarningContents(); + } + + public void saveOptions() throws IOException { + Set s = warningComboBoxes.entrySet(); + for (Iterator iterator = s.iterator(); iterator.hasNext();) { + Map.Entry entry = (Entry) iterator.next(); + String javaOption = (String) entry.getKey(); + JComboBox combo = (JComboBox)entry.getValue(); + String value = (String) combo.getSelectedItem(); + javaBuildOptions.setOption(javaOption, value); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + + private void createWarningContents() { + createWarningsEntry("Method with a constructor name",JavaOptions.WARN_METHOD_WITH_CONSTRUCTOR_NAME); + createWarningsEntry("Method overriden but not package visible",JavaOptions.WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD); + createWarningsEntry("Deprecated API's",JavaOptions.WARN_DEPRECATION); + createWarningsEntry("Hidden catch block",JavaOptions.WARN_HIDDEN_CATCH_BLOCKS); + createWarningsEntry("Unused local or private member",JavaOptions.WARN_UNUSED_LOCALS); + createWarningsEntry("Parameter is never read",JavaOptions.WARN_UNUSED_PARAMETER); + createWarningsEntry("Unused import",JavaOptions.WARN_UNUSED_IMPORTS); + createWarningsEntry("Synthetic access",JavaOptions.WARN_SYNTHETIC_ACCESS); + createWarningsEntry("Assert identifier",JavaOptions.WARN_ASSERT_IDENITIFIER); + createWarningsEntry("Non-externalized strings",JavaOptions.WARN_NON_NLS); + warningsPanel.add(warningsBox,null); + } + + private void createWarningsEntry(String labelText, String javaOptionToSet) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText(labelText); + panel.add(label,BorderLayout.WEST); + + JComboBox warnings = new JComboBox(ignoreOrWarning); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value.equals(JavaOptions.IGNORE)) { + warnings.setSelectedIndex(0); + } else { + warnings.setSelectedIndex(1); + } + panel.add(warnings,BorderLayout.EAST); + warningsBox.add(panel,null); + warningComboBoxes.put(javaOptionToSet,warnings); + } + + private void createBorders() { + warningsEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + warningsTitleBorder = new TitledBorder(warningsEtchedBorder, "Warning Options"); + warningsCompoundBorder = BorderFactory.createCompoundBorder(warningsTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + warningsTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + warningsPanel = new JPanel(); + warningsPanel.setBorder(warningsCompoundBorder); + parentPanel.add(warningsPanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java new file mode 100644 index 000000000..09eabe901 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaComplianceOptionsPanel.java @@ -0,0 +1,143 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the java compiler compliance options. + * Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaComplianceOptionsPanel extends OptionsPanel { + + private final String[] complianceLevels = new String[] {JavaOptions.VERSION_13, JavaOptions.VERSION_14, JavaOptions.VERSION_15, JavaOptions.VERSION_16}; + + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border complianceEtchedBorder; + private TitledBorder complianceTitleBorder; + private Border complianceCompoundBorder; + private JPanel compliancePanel; + private Box complianceBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private Map/*String --> JComboBox*/ complianceComboBoxes = new HashMap(); + + public JavaComplianceOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Compliance Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createComplianceContents(); + } + + public void saveOptions() throws IOException { + Set s = complianceComboBoxes.entrySet(); + for (Iterator iterator = s.iterator(); iterator.hasNext();) { + Map.Entry entry = (Entry) iterator.next(); + String javaOption = (String) entry.getKey(); + JComboBox combo = (JComboBox)entry.getValue(); + String value = (String) combo.getSelectedItem(); + javaBuildOptions.setOption(javaOption, value); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + + private void createComplianceContents() { + createComplianceEntry("AjCompiler compliance level: ",JavaOptions.COMPLIANCE_LEVEL); + createComplianceEntry("Source compatibility: ",JavaOptions.SOURCE_COMPATIBILITY_LEVEL); + createComplianceEntry("Generated class file compatibility: ",JavaOptions.TARGET_COMPATIBILITY_LEVEL); + compliancePanel.add(complianceBox); + } + + private void createComplianceEntry(String labelText, String javaOptionToSet) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText(labelText); + panel.add(label,BorderLayout.WEST); + + JComboBox levels = new JComboBox(complianceLevels); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value == null) { + // default to 1.5 + levels.setSelectedIndex(2); + } else if (value.equals(JavaOptions.VERSION_13)) { + levels.setSelectedIndex(0); + } else if (value.equals(JavaOptions.VERSION_14)){ + levels.setSelectedIndex(1); + } else if (value.equals(JavaOptions.VERSION_15)){ + levels.setSelectedIndex(2); + } else if (value.equals(JavaOptions.VERSION_16)){ + levels.setSelectedIndex(3); + } + panel.add(levels,BorderLayout.EAST); + complianceBox.add(panel,null); + complianceComboBoxes.put(javaOptionToSet,levels); + } + + + private void createBorders() { + complianceEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + complianceTitleBorder = new TitledBorder(complianceEtchedBorder, "Compliance Options"); + complianceCompoundBorder = BorderFactory.createCompoundBorder(complianceTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + complianceTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + compliancePanel = new JPanel(); + compliancePanel.setBorder(complianceCompoundBorder); + + parentPanel.add(compliancePanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java new file mode 100644 index 000000000..7d19d6a08 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaDebugOptionsPanel.java @@ -0,0 +1,148 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the java compiler debug options. + * Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaDebugOptionsPanel extends OptionsPanel { + + private final String[] debugOptions = new String[] {JavaOptions.GENERATE,JavaOptions.DO_NOT_GENERATE}; + private final String[] preserveOptions = new String[] {JavaOptions.PRESERVE,JavaOptions.OPTIMIZE}; + + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border debugEtchedBorder; + private TitledBorder debugTitleBorder; + private Border debugCompoundBorder; + private JPanel debugPanel; + private Box debugBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private Map/*String --> JComboBox*/ debugComboBoxes = new HashMap(); + + public JavaDebugOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Debug Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createDebugContents(); + } + + public void saveOptions() throws IOException { + Set s = debugComboBoxes.entrySet(); + for (Iterator iterator = s.iterator(); iterator.hasNext();) { + Map.Entry entry = (Entry) iterator.next(); + String javaOption = (String) entry.getKey(); + JComboBox combo = (JComboBox)entry.getValue(); + String value = (String) combo.getSelectedItem(); + javaBuildOptions.setOption(javaOption, value); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + private void createDebugContents() { + createDebugEntry("Add line number attributes to generated class files",JavaOptions.DEBUG_LINES); + createDebugEntry("Add source file name to generated class file",JavaOptions.DEBUG_SOURCE); + createDebugEntry("Add variable attributes to generated class files",JavaOptions.DEBUG_VARS); + createDebugEntry("Preserve unused (never read) local variables",JavaOptions.PRESERVE_ALL_LOCALS); + debugPanel.add(debugBox); + } + + private void createDebugEntry(String labelText, String javaOptionToSet) { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText(labelText); + panel.add(label,BorderLayout.WEST); + + JComboBox debug = null; + if (javaOptionToSet.equals(JavaOptions.PRESERVE_ALL_LOCALS)) { + debug = new JComboBox(preserveOptions); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value.equals(JavaOptions.PRESERVE)) { + debug.setSelectedIndex(0); + } else { + debug.setSelectedIndex(1); + } + } else { + debug = new JComboBox(debugOptions); + String value = (String) javaBuildOptions.getJavaBuildOptionsMap().get(javaOptionToSet); + if (value.equals(JavaOptions.GENERATE)) { + debug.setSelectedIndex(0); + } else { + debug.setSelectedIndex(1); + } + } + panel.add(debug,BorderLayout.EAST); + debugBox.add(panel,null); + debugComboBoxes.put(javaOptionToSet,debug); + } + + + private void createBorders() { + debugEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + debugTitleBorder = new TitledBorder(debugEtchedBorder, "Debug Options"); + debugCompoundBorder = BorderFactory.createCompoundBorder(debugTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + debugTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + debugPanel = new JPanel(); + debugPanel.setBorder(debugCompoundBorder); + + parentPanel.add(debugPanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaOtherOptionsPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaOtherOptionsPanel.java new file mode 100644 index 000000000..5ffaf13c3 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/javaoptions/JavaOtherOptionsPanel.java @@ -0,0 +1,120 @@ +/******************************************************************** + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + * Helen Hawkins - initial version (bug 148190) + *******************************************************************/ +package org.aspectj.ajde.ui.javaoptions; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.io.IOException; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.core.JavaOptions; +import org.aspectj.ajde.ui.swing.OptionsPanel; + +/** + * An options panel which displays the character encoding java + * compiler option. Users should add this to the Ajde.getOptionsFrame() + */ +public class JavaOtherOptionsPanel extends OptionsPanel { + + private static final long serialVersionUID = 4491319302490183151L; + + private JPanel parentPanel; + + private Border otherEtchedBorder; + private TitledBorder otherTitleBorder; + private Border otherCompoundBorder; + private JPanel otherPanel; + private Box otherBox = Box.createVerticalBox(); + + private JavaBuildOptions javaBuildOptions; + + private JTextField characterEncoding; + + public JavaOtherOptionsPanel(JavaBuildOptions javaBuildOptions) { + this.javaBuildOptions = javaBuildOptions; + try { + jbInit(); + this.setName("Java Other Build Options"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void loadOptions() throws IOException { + createOtherContents(); + } + + public void saveOptions() throws IOException { + String text = characterEncoding.getText(); + if (text != null ) { + javaBuildOptions.setCharacterEncoding(text); + } + } + + private void jbInit() throws Exception { + this.setLayout(new BorderLayout()); + createBorders(); + addBordersToPanel(); + this.add(parentPanel,BorderLayout.NORTH); + } + + private void createOtherContents() { + JPanel panel = new JPanel(); + panel.setLayout(new BorderLayout()); + + JLabel label = new JLabel(); + label.setFont(new java.awt.Font("Dialog", 0, 11)); + label.setText("Character encoding (will default to platform encoding)"); + panel.add(label,BorderLayout.WEST); + + characterEncoding = new JTextField(); + characterEncoding.setFont(new java.awt.Font("SansSerif", 0, 11)); + characterEncoding.setMinimumSize(new Dimension(100, 21)); + characterEncoding.setPreferredSize(new Dimension(150, 21)); + panel.add(characterEncoding,BorderLayout.EAST); + + String option = (String) javaBuildOptions.getJavaBuildOptionsMap().get( + JavaOptions.CHARACTER_ENCODING); + if (option != null) { + characterEncoding.setText(option); + } + + otherBox.add(panel,null); + otherPanel.add(otherBox); + } + + private void createBorders() { + otherEtchedBorder = BorderFactory.createEtchedBorder(Color.white, new Color(156, 156, 158)); + otherTitleBorder = new TitledBorder(otherEtchedBorder, "Other Options"); + otherCompoundBorder = BorderFactory.createCompoundBorder(otherTitleBorder, + BorderFactory.createEmptyBorder(5, 5, 5, 5)); + otherTitleBorder.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + } + + private void addBordersToPanel() { + parentPanel = new JPanel(); + parentPanel.setLayout(new BorderLayout()); + + otherPanel = new JPanel(); + otherPanel.setBorder(otherCompoundBorder); + parentPanel.add(otherPanel,BorderLayout.CENTER); + } + + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/AJButtonMenuCombo.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/AJButtonMenuCombo.java new file mode 100644 index 000000000..72b7abeba --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/AJButtonMenuCombo.java @@ -0,0 +1,154 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; + +import org.aspectj.ajde.Ajde; + +public class AJButtonMenuCombo extends JPanel { + + private static final long serialVersionUID = -4866207530403336160L; + + private JButton mainButton; + private JButton popupButton; + private JPopupMenu menu; +// private boolean depressable = false; + private boolean isPressed = false; + + public AJButtonMenuCombo(String name, + String toolTipText, + Icon icon, + JPopupMenu menu, + boolean depressable) { + + this.menu = menu; +// this.depressable = depressable; + mainButton = new JButton(); + mainButton.setIcon(icon); + mainButton.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + mainButton.setToolTipText(toolTipText); + mainButton.setPreferredSize(new Dimension(22, 20)); + mainButton.setMinimumSize(new Dimension(22, 20)); + mainButton.setMaximumSize(new Dimension(22, 20)); + + popupButton = new JButton(); + popupButton.setIcon(Ajde.getDefault().getIconRegistry().getPopupIcon()); + popupButton.setBorder(BorderFactory.createEmptyBorder()); + popupButton.setToolTipText(toolTipText); + popupButton.setPreferredSize(new Dimension(13, 20)); + popupButton.setMinimumSize(new Dimension(13, 20)); + popupButton.setMaximumSize(new Dimension(13, 20)); + + PopupListener popupListener = new PopupListener(mainButton); + + if (depressable) { + mainButton.addActionListener(new ButtonActionListener()); + } else { + mainButton.addMouseListener(popupListener); + } + + popupButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + popupButton.setBorder(null); + } + }); + + BorderUpdateListener borderUpdateListner = new BorderUpdateListener(); + mainButton.addMouseListener(borderUpdateListner); + popupButton.addMouseListener(borderUpdateListner); + + popupButton.addMouseListener(popupListener); + + this.setLayout(new BorderLayout()); + this.add(mainButton, BorderLayout.CENTER); + this.add(popupButton, BorderLayout.EAST); + + this.setMinimumSize(new Dimension(35, 20)); + this.setMaximumSize(new Dimension(35, 20)); + } + + class ButtonActionListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (isPressed) { + mainButton.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + isPressed = false; + } else { + mainButton.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); + isPressed = true; + } + } + } + + + class BorderUpdateListener extends MouseAdapter { + public void mouseEntered(MouseEvent e) { + popupButton.setBorder(AjdeWidgetStyles.RAISED_BEVEL_BORDER); + mainButton.setBorder(AjdeWidgetStyles.RAISED_BEVEL_BORDER); + } + + public void mouseExited(MouseEvent e) { + popupButton.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + if (isPressed) { + mainButton.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); + } else { + mainButton.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + } + } + } + + class PopupListener extends MouseAdapter { + private JButton button; + + public PopupListener(JButton button) { + this.button = button; + } + + public void mousePressed(MouseEvent e) { + maybeShowPopup(e); + } + + public void mouseReleased(MouseEvent e) { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) { + menu.show(e.getComponent(), button.getX(), button.getY() + popupButton.getHeight()); + } + } + + public void setEnabled(boolean enabled) { + mainButton.setEnabled(enabled); + popupButton.setEnabled(enabled); + } + + public void setMenu(JPopupMenu menu) { + this.menu = menu; + this.repaint(); + } + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/AjdeWidgetStyles.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/AjdeWidgetStyles.java new file mode 100644 index 000000000..f0637446a --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/AjdeWidgetStyles.java @@ -0,0 +1,35 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.Color; +import java.awt.Font; + +import javax.swing.BorderFactory; +import javax.swing.border.BevelBorder; +import javax.swing.border.Border; + +public interface AjdeWidgetStyles { + + public static final Font DEFAULT_LABEL_FONT = new java.awt.Font("SansSerif", 0, 11); + public static final Border DEFAULT_BORDER = BorderFactory.createEmptyBorder(); + public static final Border LOWERED_BEVEL_BORDER = BorderFactory.createBevelBorder(BevelBorder.LOWERED); + public static final Border RAISED_BEVEL_BORDER = BorderFactory.createBevelBorder(BevelBorder.RAISED); + public static final Color DEFAULT_BACKGROUND_COLOR = Color.lightGray; + + public static final Color LINK_NODE_COLOR = new Color(0, 0, 255); + public static final Color LINK_NODE_NO_SOURCE_COLOR = new Color(150, 150, 255); + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserStructureViewToolPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserStructureViewToolPanel.java new file mode 100644 index 000000000..6988536da --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserStructureViewToolPanel.java @@ -0,0 +1,366 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Iterator; + +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JRadioButtonMenuItem; +import javax.swing.JSeparator; +import javax.swing.border.Border; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.GlobalStructureView; +import org.aspectj.ajde.ui.StructureView; +import org.aspectj.ajde.ui.StructureViewProperties; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +public class BrowserStructureViewToolPanel extends JPanel { + + private static final long serialVersionUID = 7960528108612681776L; + + private StructureView currentView; + private StructureViewPanel viewPanel; + protected BorderLayout borderLayout1 = new BorderLayout(); + protected Border border1; + protected Border border2; + AJButtonMenuCombo granularityCombo; + AJButtonMenuCombo filterCombo; + AJButtonMenuCombo relationsCombo; + JPanel buttons_panel = new JPanel(); + JPanel spacer_panel = new JPanel(); + BorderLayout borderLayout2 = new BorderLayout(); + BorderLayout borderLayout3 = new BorderLayout(); + JPanel view_panel = new JPanel(); + JComboBox view_comboBox = null; + JLabel view_label = new JLabel(); + BorderLayout borderLayout4 = new BorderLayout(); + + public BrowserStructureViewToolPanel( + java.util.List structureViews, + StructureView currentView, + StructureViewPanel viewPanel) { + + this.currentView = currentView; + this.viewPanel = viewPanel; + view_comboBox = new JComboBox(); + view_comboBox.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); + + for (Iterator it = structureViews.iterator(); it.hasNext(); ) { + view_comboBox.addItem(it.next()); + } + + try { + jbInit(); + } catch (Exception e) { + Message msg = new Message("Could not initialize GUI.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + initToolBar(); + } + + private void initToolBar() { + try { + granularityCombo = new AJButtonMenuCombo( + "Visible granularity", + "Visible granularity", + Ajde.getDefault().getIconRegistry().getGranularityIcon(), + createGranularityMenu(), + false); + + filterCombo = new AJButtonMenuCombo( + "Filter members", + "Filter members", + Ajde.getDefault().getIconRegistry().getFilterIcon(), + createFilterMenu(), + false); + + relationsCombo = new AJButtonMenuCombo( + "Filter associations", + "Filter associations", + Ajde.getDefault().getIconRegistry().getRelationsIcon(), + createRelationsMenu(), + false); + + buttons_panel.add(granularityCombo, BorderLayout.WEST); + buttons_panel.add(filterCombo, BorderLayout.CENTER); + buttons_panel.add(relationsCombo, BorderLayout.EAST); + } catch(Exception e) { + Message msg = new Message("Could not initialize GUI.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + private JPopupMenu createFilterMenu() { + JPopupMenu filterMenu = new JPopupMenu(); + IProgramElement.Accessibility[] accessibility = IProgramElement.Accessibility.ALL; + for (int i = 0; i < accessibility.length; i++) { + CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(accessibility[i]); + menuItem.setIcon(Ajde.getDefault().getIconRegistry().getAccessibilitySwingIcon(accessibility[i])); + filterMenu.add(menuItem); + } + filterMenu.add(new JSeparator()); + + IProgramElement.Kind[] kinds = IProgramElement.Kind.ALL; + for (int i = 0; i < kinds.length; i++) { + if (kinds[i].isMember()) { + CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(kinds[i]); + menuItem.setIcon((Icon)Ajde.getDefault().getIconRegistry().getIcon(kinds[i]).getIconResource()); + filterMenu.add(menuItem); + } + } + filterMenu.add(new JSeparator()); + + IProgramElement.Modifiers[] modifiers = IProgramElement.Modifiers.ALL; + for (int i = 0; i < modifiers.length; i++) { + CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(modifiers[i]); + filterMenu.add(menuItem); + } + return filterMenu; + } + + private JPopupMenu createRelationsMenu() { + JPopupMenu relationsMenu = new JPopupMenu(); + + java.util.List relations = Ajde.getDefault().getStructureViewManager().getAvailableRelations(); + for (Iterator it = relations.iterator(); it.hasNext(); ) { + IRelationship.Kind relation = (IRelationship.Kind)it.next(); + CheckBoxSelectionMenuButton menuItem = new CheckBoxSelectionMenuButton(relation); + menuItem.setIcon((Icon)Ajde.getDefault().getIconRegistry().getIcon(relation).getIconResource()); + relationsMenu.add(menuItem); + } + + return relationsMenu; + } + + private JPopupMenu createGranularityMenu() { + JPopupMenu orderMenu = new JPopupMenu(); + + StructureViewProperties.Granularity[] granularity = StructureViewProperties.Granularity.ALL; + ButtonGroup group = new ButtonGroup(); + for (int i = 0; i < granularity.length; i++) { + RadioSelectionMenuButton menuItem = new RadioSelectionMenuButton(granularity[i], group); + orderMenu.add(menuItem); + if (granularity[i].equals(StructureViewProperties.Granularity.MEMBER)) { + menuItem.setSelected(true); + } + } + return orderMenu; + } + + private class RadioSelectionMenuButton extends JRadioButtonMenuItem { + + private static final long serialVersionUID = -879644981405801807L; + + public RadioSelectionMenuButton(StructureViewProperties.Granularity granularity, ButtonGroup group) { + super(granularity.toString()); + super.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); + group.add(this); + this.addActionListener(new RadioSelectionMenuActionListener(granularity)); + } + } + + private class RadioSelectionMenuActionListener implements ActionListener { + private StructureViewProperties.Granularity granularity; + + public RadioSelectionMenuActionListener(StructureViewProperties.Granularity granularity) { + this.granularity = granularity; + } + + public void actionPerformed(ActionEvent e) { + currentView.getViewProperties().setGranularity(granularity); + Ajde.getDefault().getStructureViewManager().refreshView(currentView); + } + } + + private class CheckBoxSelectionMenuButton extends JCheckBoxMenuItem { + + private static final long serialVersionUID = -4555502313984854787L; + + public CheckBoxSelectionMenuButton(String name) { + super(name); + this.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); + this.setBackground(AjdeWidgetStyles.DEFAULT_BACKGROUND_COLOR); + //super.setSelected(true); + } + + public CheckBoxSelectionMenuButton(IProgramElement.Accessibility accessibility) { + this(accessibility.toString()); + this.addActionListener(new CheckBoxSelectionMenuActionListener(accessibility)); + } + + public CheckBoxSelectionMenuButton(IProgramElement.Kind kind) { + this(kind.toString()); + this.addActionListener(new CheckBoxSelectionMenuActionListener(kind)); + } + + public CheckBoxSelectionMenuButton(IProgramElement.Modifiers modifiers) { + this(modifiers.toString()); + this.addActionListener(new CheckBoxSelectionMenuActionListener(modifiers)); + } + + public CheckBoxSelectionMenuButton(StructureViewProperties.Sorting sorting) { + this(sorting.toString()); + this.addActionListener(new CheckBoxSelectionMenuActionListener(sorting)); + } + + public CheckBoxSelectionMenuButton(IRelationship.Kind relation) { + this(relation.toString()); + this.addActionListener(new CheckBoxSelectionMenuActionListener(relation)); + } + } + + /** + * Ewwwwww! + */ + private class CheckBoxSelectionMenuActionListener implements ActionListener { + private IProgramElement.Accessibility accessibility = null; + private IProgramElement.Kind kind = null; + private IProgramElement.Modifiers modifiers = null; + private StructureViewProperties.Sorting sorting = null; + private IRelationship.Kind relation = null; + + public CheckBoxSelectionMenuActionListener(IProgramElement.Accessibility accessibility) { + this.accessibility = accessibility; + } + + public CheckBoxSelectionMenuActionListener(IProgramElement.Kind kind) { + this.kind = kind; + } + + public CheckBoxSelectionMenuActionListener(IProgramElement.Modifiers modifiers) { + this.modifiers = modifiers; + } + + public CheckBoxSelectionMenuActionListener(StructureViewProperties.Sorting sorting) { + this.sorting = sorting; + } + + public CheckBoxSelectionMenuActionListener(IRelationship.Kind relationKind) { + this.relation = relationKind; + } + + public void actionPerformed(ActionEvent e) { + if (!(e.getSource() instanceof CheckBoxSelectionMenuButton)) return; + CheckBoxSelectionMenuButton checkMenu = (CheckBoxSelectionMenuButton)e.getSource(); + if (accessibility != null) { + if (checkMenu.isSelected()) { + currentView.getViewProperties().addFilteredMemberAccessibility(accessibility); + } else { + currentView.getViewProperties().removeFilteredMemberAccessibility(accessibility); + } + } else if (kind != null) { + if (checkMenu.isSelected()) { + currentView.getViewProperties().addFilteredMemberKind(kind); + } else { + currentView.getViewProperties().removeFilteredMemberKind(kind); + } + } else if (modifiers != null) { + if (checkMenu.isSelected()) { + currentView.getViewProperties().addFilteredMemberModifiers(modifiers); + } else { + currentView.getViewProperties().removeFilteredMemberModifiers(modifiers); + } + } else if (sorting != null) { + if (checkMenu.isSelected()) { + currentView.getViewProperties().setSorting(sorting); + } else { + currentView.getViewProperties().setSorting(StructureViewProperties.Sorting.DECLARATIONAL); + } + } else if (relation != null) { + if (checkMenu.isSelected()) { + currentView.getViewProperties().removeRelation(relation); + } else { + currentView.getViewProperties().addRelation(relation); + } + } + Ajde.getDefault().getStructureViewManager().refreshView(currentView); + } + } + +// public void highlightNode(ProgramElementNode node) { +// treeManager.navigationAction(node, true, true); +// } + +// private void order_comboBox_actionPerformed(ActionEvent e) { +// Ajde.getDefault().getStructureViewManager().refreshView( +// currentView +// ); +// } + + private void jbInit() throws Exception { + this.setLayout(borderLayout2); + buttons_panel.setLayout(borderLayout3); + buttons_panel.setMinimumSize(new Dimension(105, 10)); + buttons_panel.setPreferredSize(new Dimension(105, 10)); + view_comboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + view_comboBox_actionPerformed(e); + } + }); + view_label.setFont(new java.awt.Font("Dialog", 0, 11)); + view_label.setText(" Global View "); + view_comboBox.setFont(new java.awt.Font("SansSerif", 0, 11)); + view_comboBox.setPreferredSize(new Dimension(125, 22)); + view_panel.setLayout(borderLayout4); + view_panel.add(view_label, BorderLayout.WEST); + this.add(buttons_panel, BorderLayout.EAST); + this.add(spacer_panel, BorderLayout.CENTER); + this.add(view_panel, BorderLayout.WEST); + view_panel.add(view_comboBox, BorderLayout.CENTER); + + } + +// private void order_button_actionPerformed(ActionEvent e) { +// +// } +// +// private void orderPopup_button_actionPerformed(ActionEvent e) { +// +// } + + void separator_button_actionPerformed(ActionEvent e) { + + } + + void view_comboBox_actionPerformed(ActionEvent e) { + StructureView view = (StructureView)view_comboBox.getSelectedItem(); + viewPanel.setCurrentView(view); + if (((GlobalStructureView)view).getGlobalViewProperties().getHierarchy() + == StructureViewProperties.Hierarchy.DECLARATION) { + granularityCombo.setEnabled(true); + relationsCombo.setEnabled(true); + filterCombo.setEnabled(true); + } else { + granularityCombo.setEnabled(false); + relationsCombo.setEnabled(false); + filterCombo.setEnabled(false); + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserView.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserView.java new file mode 100644 index 000000000..d41827a41 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserView.java @@ -0,0 +1,335 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.MouseEvent; +import java.io.File; +import java.util.Iterator; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JSplitPane; +import javax.swing.JToggleButton; +import javax.swing.JToolBar; +import javax.swing.ListCellRenderer; +import javax.swing.border.Border; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.IconRegistry; +import org.aspectj.asm.IProgramElement; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * @author Mik Kersten + */ +class BrowserView extends JPanel { + private static final long serialVersionUID = 1L; +// private BrowserViewPanel masterView; + private BrowserViewPanel slaveView; + private boolean slaveViewVisible = false; + private String lastSelectedConfig = ""; + + private IconRegistry icons = null; + private BorderLayout borderLayout1 = new BorderLayout(); + private Border default_border; + private JPanel toolBar_panel = new JPanel(); + private BorderLayout borderLayout2 = new BorderLayout(); + JPanel mainToolBar_panel = new JPanel(); + JToolBar config_toolBar = new JToolBar(); + JComboBox configs_comboBox = null; + BorderLayout borderLayout3 = new BorderLayout(); + JToolBar nav_toolBar = new JToolBar(); + JButton forward_button = new JButton(); + JButton back_button = new JButton(); + GridLayout gridLayout1 = new GridLayout(); + JSplitPane views_splitPane = new JSplitPane(); + JToolBar command_toolBar = new JToolBar(); + JToggleButton splitView_button = new JToggleButton(); + JToggleButton zoomToFile_button = new JToggleButton(); + JButton joinpointProbe_button = new JButton(); + + public BrowserView(BrowserViewPanel masterView, BrowserViewPanel slaveView, IconRegistry icons) { + try { + // this.masterView = masterView; + this.slaveView = slaveView; + this.icons = icons; + configs_comboBox = new JComboBox(Ajde.getDefault().getBuildConfigManager().getAllBuildConfigFiles().toArray()); + configs_comboBox.setRenderer(new ConfigsCellRenderer()); +// configs_comboBox.addItemListener(new ItemListener() { +// public void itemStateChanged(ItemEvent e) { +// Ajde.getDefault().getConfigurationManager().setCurrConfigFile(lastSelectedConfig); +// } +// }); + + if (Ajde.getDefault().getBuildConfigManager().getAllBuildConfigFiles().size() > 0) { + Ajde.getDefault().getBuildConfigManager().setActiveConfigFile((String)Ajde.getDefault().getBuildConfigManager().getAllBuildConfigFiles().get(0)); + } + + jbInit(); + fixButtonBorders(); + views_splitPane.add(masterView, JSplitPane.TOP); + views_splitPane.add(slaveView, JSplitPane.BOTTOM); + setSlaveViewVisible(false); + + nav_toolBar.remove(joinpointProbe_button); + } catch(Exception e) { + Message msg = new Message("Could not initialize GUI.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + + } + } + + public void setSlaveViewVisible(boolean visible) { + slaveViewVisible = visible; + if (visible) { + views_splitPane.add(slaveView, JSplitPane.BOTTOM); + views_splitPane.setDividerLocation(this.getHeight()-250); + //masterView.scrollToHighlightedNode(); + } else { + views_splitPane.remove(slaveView); + views_splitPane.setDividerLocation(this.getHeight()); + } + } + + public boolean isSlaveViewVisible() { + return slaveViewVisible; + } + + public void updateConfigs(java.util.List configsList) { + configs_comboBox.removeAllItems(); + for (Iterator it = configsList.iterator(); it.hasNext(); ) { + configs_comboBox.addItem(it.next()); + } + } + + public void setSelectedConfig(String config) { + for (int i = 0; i < configs_comboBox.getItemCount(); i++) { + if (configs_comboBox.getItemAt(i).equals(config)) { + configs_comboBox.setSelectedIndex(i); + } + } + } + + public String getSelectedConfig() { + return (String)configs_comboBox.getSelectedItem(); + } + + /** + * @todo get rid of this method and make the GUI-designer generated code work properly + */ + private void fixButtonBorders() { + back_button.setBorder(BorderFactory.createEmptyBorder()); + forward_button.setBorder(BorderFactory.createEmptyBorder()); + zoomToFile_button.setBorder(BorderFactory.createEmptyBorder()); + splitView_button.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 0, Color.blue)); + } + + private void jbInit() throws Exception { + default_border = BorderFactory.createEmptyBorder(); + this.setLayout(borderLayout1); + toolBar_panel.setLayout(borderLayout2); + toolBar_panel.setBorder(BorderFactory.createEtchedBorder()); + config_toolBar.setBorder(default_border); + config_toolBar.setFloatable(false); + configs_comboBox.setPreferredSize(new Dimension(200, 20)); + configs_comboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + configs_comboBox_actionPerformed(e); + } + }); + configs_comboBox.setMinimumSize(new Dimension(40, 20)); + configs_comboBox.setFont(new java.awt.Font("SansSerif", 0, 11)); + mainToolBar_panel.setLayout(borderLayout3); + nav_toolBar.setFloatable(false); + nav_toolBar.setBorder(default_border); + forward_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + forward_button_actionPerformed(e); + } + }); + forward_button.setIcon(icons.getForwardIcon()); + forward_button.setToolTipText("Navigate forward"); + forward_button.setPreferredSize(new Dimension(20, 20)); + forward_button.setMinimumSize(new Dimension(20, 20)); + forward_button.setBorder(default_border); + forward_button.setMaximumSize(new Dimension(24, 20)); + back_button.setMaximumSize(new Dimension(24, 20)); + back_button.setBorder(default_border); + back_button.setMinimumSize(new Dimension(20, 20)); + back_button.setPreferredSize(new Dimension(20, 20)); + back_button.setToolTipText("Navigate back"); + back_button.setIcon(icons.getBackIcon()); + back_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + back_button_actionPerformed(e); + } + }); +// structureViews_box.add(comment_editorPane, null); + views_splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); + views_splitPane.setDividerSize(2); + command_toolBar.setBorder(default_border); + command_toolBar.setFloatable(false); + splitView_button.setFont(new java.awt.Font("Dialog", 0, 11)); + splitView_button.setBorder(default_border); + splitView_button.setMaximumSize(new Dimension(24, 24)); + splitView_button.setPreferredSize(new Dimension(20, 20)); + splitView_button.setToolTipText("Togge split-tree view mode"); + splitView_button.setIcon(icons.getSplitStructureViewIcon()); + splitView_button.setSelectedIcon(icons.getMergeStructureViewIcon()); + splitView_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + //splitView_button_actionPerformed(e); + } + }); + zoomToFile_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + //zoomToFile_button_actionPerformed(e); + } + }); + zoomToFile_button.setIcon(icons.getZoomStructureToFileModeIcon()); + zoomToFile_button.setSelectedIcon(icons.getZoomStructureToGlobalModeIcon()); + zoomToFile_button.setBorder(BorderFactory.createRaisedBevelBorder()); + zoomToFile_button.setMaximumSize(new Dimension(24, 24)); + zoomToFile_button.setPreferredSize(new Dimension(20, 20)); + zoomToFile_button.setToolTipText("Toggle file-view mode"); + zoomToFile_button.setFont(new java.awt.Font("Dialog", 0, 11)); + joinpointProbe_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + joinpointProbe_button_actionPerformed(e); + } + }); + joinpointProbe_button.setIcon(icons.getStructureSwingIcon(IProgramElement.Kind.POINTCUT)); + joinpointProbe_button.setToolTipText("Create joinpoint probe"); + joinpointProbe_button.setPreferredSize(new Dimension(20, 20)); + joinpointProbe_button.setMinimumSize(new Dimension(20, 20)); + joinpointProbe_button.setBorder(default_border); + joinpointProbe_button.setMaximumSize(new Dimension(24, 20)); + this.add(toolBar_panel, BorderLayout.NORTH); + toolBar_panel.add(mainToolBar_panel, BorderLayout.NORTH); + mainToolBar_panel.add(config_toolBar, BorderLayout.CENTER); + config_toolBar.add(configs_comboBox, null); + mainToolBar_panel.add(nav_toolBar, BorderLayout.EAST); + nav_toolBar.add(splitView_button, null); + nav_toolBar.add(zoomToFile_button, null); + nav_toolBar.add(joinpointProbe_button, null); + nav_toolBar.add(back_button, null); + nav_toolBar.add(forward_button, null); + mainToolBar_panel.add(command_toolBar, BorderLayout.WEST); + this.add(views_splitPane, BorderLayout.CENTER); + views_splitPane.setDividerLocation(400); + } + + void forward_button_actionPerformed(ActionEvent e) { + //AjdeUIManager.getDefault().getViewManager().navigateForwardAction(); + } + void back_button_actionPerformed(ActionEvent e) { + //AjdeUIManager.getDefault().getViewManager().navigateBackAction(); + } + +// void splitView_button_actionPerformed(ActionEvent e) { +// AjdeUIManager.getDefault().getViewManager().setSplitViewMode(!slaveViewVisible); +// } + + static class ConfigsCellRenderer extends JLabel implements ListCellRenderer { + + private static final long serialVersionUID = 8795959045339903340L; + + public ConfigsCellRenderer() { + setOpaque(true); + } + + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + if (value == null) return this; + + java.io.File file = new File(value.toString()); + setText(file.getName()); + setBackground(isSelected ? Color.gray : Color.lightGray); +// setForeground(isSelected ? Color.lightGray : Color.gray); + return this; + } + } + + void configDesigner_button_mouseClicked(MouseEvent e) { + + } + void configDesigner_button_mousePressed(MouseEvent e) { + + } + void configDesigner_button_mouseReleased(MouseEvent e) { + + } + void configDesigner_button_mouseEntered(MouseEvent e) { + + } + void configDesigner_button_mouseExited(MouseEvent e) { + + } + void configDesigner_button_actionPerformed(ActionEvent e) { + + } + void viewManager_button_mouseClicked(MouseEvent e) { + + } + void viewManager_button_mousePressed(MouseEvent e) { + + } + void viewManager_button_mouseReleased(MouseEvent e) { + + } + void viewManager_button_mouseEntered(MouseEvent e) { + + } + void viewManager_button_mouseExited(MouseEvent e) { + + } + void viewManager_button_actionPerformed(ActionEvent e) { + + } + +// void zoomToFile_button_actionPerformed(ActionEvent e) { +// AjdeUIManager.getDefault().getViewManager().setGlobalMode(!AjdeUIManager.getDefault().getViewManager().isGlobalMode()); +// AjdeUIManager.getDefault().getViewManager().updateView(); +// } + + void configs_comboBox_actionPerformed(ActionEvent e) { + if (configs_comboBox.getSelectedItem() != null) { + if (!configs_comboBox.getSelectedItem().toString().equals(lastSelectedConfig)) { + //TopManager.INSTANCE.VIEW_MANAGER.readStructureView(); + lastSelectedConfig = configs_comboBox.getSelectedItem().toString(); + Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(lastSelectedConfig); + } + } + } + + private void joinpointProbe_button_actionPerformed(ActionEvent e) { + //joinpointProbeWizard(); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewManager.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewManager.java new file mode 100644 index 000000000..cd01dec70 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewManager.java @@ -0,0 +1,95 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.util.ArrayList; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.GlobalStructureView; +import org.aspectj.ajde.ui.GlobalViewProperties; +import org.aspectj.ajde.ui.StructureViewProperties; + +/** + * Responsible for displaying and controlling the configuration and output of a + * master and slave structure view. + * + * @author Mik Kersten + */ +public class BrowserViewManager { + + private StructureViewPanel browserPanel = null; +// private boolean globalMode = true; +// private boolean splitViewMode = false; +// private IconRegistry icons; +// +// private Stack backHistory = new Stack(); +// private Stack forwardHistory = new Stack(); +// private IProgramElement currNode = null; + + private final GlobalStructureView DECLARATION_VIEW; + private final GlobalStructureView CROSSCUTTING_VIEW; + private final GlobalStructureView INHERITANCE_VIEW; + + private final GlobalViewProperties DECLARATION_VIEW_PROPERTIES; + private final GlobalViewProperties CROSSCUTTING_VIEW_PROPERTIES; + private final GlobalViewProperties INHERITANCE_VIEW_PROPERTIES; + + public BrowserViewManager() { + java.util.List views = new ArrayList(); + views.add(DECLARATION_VIEW); + views.add(CROSSCUTTING_VIEW); + views.add(INHERITANCE_VIEW); + browserPanel = new StructureViewPanel(views); + } + + public StructureViewPanel getBrowserPanel() { + return browserPanel; + } + + public void extractAndInsertSignatures(java.util.List signatures, boolean calls) { + PointcutWizard pointcutWizard = new PointcutWizard(signatures); + pointcutWizard.setVisible(true); + pointcutWizard.setLocation(Ajde.getDefault().getRootFrame().getX()+100, Ajde.getDefault().getRootFrame().getY()+100); + } + + { + DECLARATION_VIEW_PROPERTIES = new GlobalViewProperties(StructureViewProperties.Hierarchy.DECLARATION); + CROSSCUTTING_VIEW_PROPERTIES = new GlobalViewProperties(StructureViewProperties.Hierarchy.CROSSCUTTING); + INHERITANCE_VIEW_PROPERTIES = new GlobalViewProperties(StructureViewProperties.Hierarchy.INHERITANCE); + +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(IRelationship.Kind.ADVICE); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(IRelationship.Kind.ADVICE); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(IRelationship.Kind.ADVICE); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(AdviceAssociation.METHOD_CALL_SITE_RELATION); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(AdviceAssociation.CONSTRUCTOR_RELATION); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(AdviceAssociation.CONSTRUCTOR_CALL_SITE_RELATION); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(AdviceAssociation.HANDLER_RELATION); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(AdviceAssociation.INITIALIZER_RELATION); +// CROSSCUTTING_VIEW_PROPERTIES.addRelation(AdviceAssociation.FIELD_ACCESS_RELATION); +// +// INHERITANCE_VIEW_PROPERTIES.addRelation(InheritanceAssociation.IMPLEMENTS_RELATION); +// INHERITANCE_VIEW_PROPERTIES.addRelation(InheritanceAssociation.INHERITS_MEMBERS_RELATION); +// INHERITANCE_VIEW_PROPERTIES.addRelation(InheritanceAssociation.INHERITS_RELATION); + + DECLARATION_VIEW_PROPERTIES.setRelations(Ajde.getDefault().getStructureViewManager().getAvailableRelations()); + + CROSSCUTTING_VIEW = Ajde.getDefault().getStructureViewManager().createGlobalView(CROSSCUTTING_VIEW_PROPERTIES); + INHERITANCE_VIEW = Ajde.getDefault().getStructureViewManager().createGlobalView(INHERITANCE_VIEW_PROPERTIES); + DECLARATION_VIEW = Ajde.getDefault().getStructureViewManager().createGlobalView(DECLARATION_VIEW_PROPERTIES); + } +} + + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewPanel.java new file mode 100644 index 000000000..0b15049b6 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewPanel.java @@ -0,0 +1,168 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.util.Iterator; + +import javax.swing.JComboBox; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSlider; +import javax.swing.JToolBar; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.IconRegistry; +import org.aspectj.ajde.ui.GlobalStructureView; +import org.aspectj.ajde.ui.IStructureViewNode; +import org.aspectj.ajde.ui.StructureView; +import org.aspectj.ajde.ui.StructureViewProperties; +import org.aspectj.ajde.ui.StructureViewRenderer; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * Represents the configuration of a structure view of the system, rendered + * by the <CODE>StructureTreeManager</CODE>. + * + * @author Mik Kersten + */ +public class BrowserViewPanel extends JPanel implements StructureViewRenderer { + + private static final long serialVersionUID = 2201330630036486567L; + + private StructureTreeManager treeManager; + //private StructureView structureView = null; + //private int depthSliderVal = 0; + private JComboBox view_comboBox = null; + + private BorderLayout borderLayout1 = new BorderLayout(); + private JToolBar view_toolBar = new JToolBar(); + private JSlider depth_slider = new JSlider(); + JScrollPane tree_ScrollPane = new JScrollPane(); + JPanel tree_panel = new JPanel(); + BorderLayout borderLayout2 = new BorderLayout(); + +// private final StructureViewRenderer VIEW_LISTENER = new StructureViewRenderer() { +// public void viewUpdated() { +// updateTree(); +// } +// }; + + public BrowserViewPanel(IconRegistry icons, java.util.List views, StructureViewProperties.Hierarchy visibleViewHierarchy) { + try { + view_comboBox = new JComboBox(views.toArray()); + for (Iterator it = views.iterator(); it.hasNext(); ) { + StructureViewProperties.Hierarchy hierarchy = (StructureViewProperties.Hierarchy)it.next(); + if (hierarchy == visibleViewHierarchy) { + view_comboBox.setSelectedItem(hierarchy); + } + } + //GlobalViewProperties visibleView = (GlobalViewProperties)viewProperties.get(visibleViewHierarchy.toString()); + treeManager = new StructureTreeManager();//, visibleView); + jbInit(); + initDepthSlider(); + tree_ScrollPane.getViewport().add(treeManager.getStructureTree(), null); + + //Ajde.getDefault().getViewManager().getFileStructureView().addListener(VIEW_LISTENER); + } + catch(Exception e) { + Message msg = new Message("Could not initialize GUI.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + public void setActiveNode(IStructureViewNode node) { + throw new RuntimeException("not implemented"); + } + + public void setActiveNode(IStructureViewNode activeNode, int lineOffset) { + throw new RuntimeException("not implemented"); + } + +// public void highlightNode(ProgramElementNode node) { +// treeManager.navigationAction(node, true, true); +// } + +// void updateTree() { +// StructureViewProperties.Hierarchy hierarchy = ((StructureViewProperties.Hierarchy)view_comboBox.getSelectedItem()); +// GlobalStructureView structureView = Ajde.getDefault().getStructureViewManager().getGlobalStructureView(hierarchy); +// treeManager.updateTree(structureView, depthSliderVal); +// } + + public void updateView(StructureView structureView) { + if (structureView instanceof GlobalStructureView) { + treeManager.updateTree(structureView); + } + } + + void updateTree(String filePath) { + //treeManager.updateTree(Ajde.getDefault().getViewManager().getFileStructureView(filePath)); + } + + private void initDepthSlider() { + depth_slider.setMinimum(0); + depth_slider.setMaximum(9); + depth_slider.setMinorTickSpacing(1); + depth_slider.setValue(9); + depth_slider.setSnapToTicks(true); + depth_slider.setPaintTrack(true); + depth_slider.setPaintTicks(true); +// this.depth_slider.addChangeListener( +// new ChangeListener() { +// public void stateChanged(ChangeEvent e) { +// depthSliderVal = depth_slider.getValue(); +// //AjdeUIManager.getDefault().getViewManager().updateView(); +// } +// }); +// depthSliderVal = depth_slider.getValue(); + } + + private void view_comboBox_actionPerformed(ActionEvent e) { + //updateTree(DECLARATION_VIEW); + throw new RuntimeException("not implemented"); + } + + private void jbInit() throws Exception { + tree_panel.setLayout(borderLayout2); + this.setLayout(borderLayout1); + view_comboBox.setPreferredSize(new Dimension(200, 20)); + view_comboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + view_comboBox_actionPerformed(e); + } + }); + view_comboBox.setMinimumSize(new Dimension(40, 20)); + view_comboBox.setFont(new java.awt.Font("SansSerif", 0, 11)); + depth_slider.setMaximumSize(new Dimension(32767, 25)); + depth_slider.setToolTipText(""); + depth_slider.setMinimumSize(new Dimension(30, 20)); + depth_slider.setBorder(null); + depth_slider.setPreferredSize(new Dimension(30, 25)); + depth_slider.setMaximum(3); + depth_slider.setPaintTicks(true); + depth_slider.setValue(1); + depth_slider.setPaintLabels(true); + view_toolBar.setFloatable(false); + this.add(view_toolBar, BorderLayout.NORTH); + view_toolBar.add(view_comboBox, null); + view_toolBar.add(depth_slider, null); + this.add(tree_panel, BorderLayout.CENTER); + tree_panel.add(tree_ScrollPane, BorderLayout.CENTER); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewTreeListener.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewTreeListener.java new file mode 100644 index 000000000..8e88a38a4 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BrowserViewTreeListener.java @@ -0,0 +1,165 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.AbstractAction; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; + +import org.aspectj.ajde.Ajde; +import org.aspectj.asm.IProgramElement; + +/** + * @author Mik Kersten + */ +class BrowserViewTreeListener implements TreeSelectionListener, MouseListener { + private StructureTree tree = null; + + public BrowserViewTreeListener(StructureTree tree) { + this.tree = tree; + } + + public void valueChanged(TreeSelectionEvent e) { } + + public void mouseEntered(MouseEvent e) { } + + public void mouseExited(MouseEvent e) { } + + public void mousePressed(MouseEvent e) { } + + public void mouseReleased(MouseEvent e) { } + + public void mouseClicked(MouseEvent e) { + singleClickNavigation(e); + //doubleClickNavigation(e); + maybeShowPopup(e); + } + + public void singleClickNavigation(MouseEvent e) { + SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent(); + if (treeNode != null && !e.isControlDown() && !e.isShiftDown() && e.getModifiers() != 4) { + IProgramElement currNode = (IProgramElement)treeNode.getUserObject(); + if (currNode!=null && !e.isControlDown() + && !e.isShiftDown() && e.getModifiers() != 4) { + //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView((ProgramElementNode)currNode); + //if (AjdeUIManager.getDefault().getViewManager().isSplitViewMode()) { + // AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView((ProgramElementNode)currNode); + //} + } +// else if (currNode instanceof LinkNode) { + //if (!AjdeUIManager.getDefault().getViewManager().isSplitViewMode()) { + // AjdeUIManager.getDefault().getViewManager().showNodeInMasterView((LinkNode)currNode); + //} else { + // AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView(((LinkNode)currNode).getProgramElementNode()); + //} +// } + } + } + + public void doubleClickNavigation(MouseEvent e) { +// int clickCount = e.getClickCount(); + SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent(); + if (treeNode != null) { + IProgramElement currNode = (IProgramElement)treeNode.getUserObject(); + if (currNode!=null && !e.isControlDown() && !e.isShiftDown() + && e.getModifiers() != 4) { + //AjdeUIManager.getDefault().getViewManager().showNodeInMasterView(((LinkNode)currNode).getProgramElementNode()); + //AjdeUIManager.getDefault().getViewManager().showNodeInSlaveView(((LinkNode)currNode).getProgramElementNode()); + } +// else if (currNode instanceof LinkNode) { +// if (clickCount == 1) { +// //AjdeUIManager.getDefault().getViewManager().showLink((LinkNode)currNode); +// } else if (clickCount == 2) { +// //navigationAction((ProgramElementNode)((LinkNode)currNode).getProgramElementNode(), true, true); +// } +// } + } + } + + /** + * @todo this should probably use <CODE>e.isPopupTrigger()</CODE> but that + * doesn't work for some reason, so we just check if the right mouse button + * has been clicked. + */ + private void maybeShowPopup(MouseEvent e) { + if (e.getModifiers() == InputEvent.BUTTON3_MASK && tree.getSelectionCount() > 0) { +// TreePath[] selectionPaths = tree.getSelectionPaths(); + final List signatures = new ArrayList(); +// for (int i = 0; i < selectionPaths.length; i++) { +// IProgramElement currNode = (IProgramElement)((SwingTreeViewNode)selectionPaths[i].getLastPathComponent()).getUserObject(); +//// if (currNode instanceof LinkNode || currNode instanceof IProgramElement) { +//// signatures.add(currNode); +//// } +// } + + JPopupMenu popup = new JPopupMenu(); + JMenuItem showSourcesItem = new JMenuItem("Display sources", Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.CODE)); + showSourcesItem.setFont(new java.awt.Font("Dialog", 0, 11)); + showSourcesItem.addActionListener(new AbstractAction() { + + private static final long serialVersionUID = 1L; + + public void actionPerformed(ActionEvent e) { + //AjdeUIManager.getDefault().getViewManager().showSourcesNodes(signatures); + // USED THE FOLLOWING FROM: BrowserViewManager: +// public void showSourcesNodes(java.util.List nodes) { +// for (Iterator it = nodes.iterator(); it.hasNext(); ) { +// ProgramElementNode currNode = null; +// IProgramElement IProgramElement = (IProgramElement)it.next(); +// if (IProgramElement instanceof LinkNode) { +// currNode = ((LinkNode)IProgramElement).getProgramElementNode(); +// } else { +// currNode = (ProgramElementNode)IProgramElement; +// } +// ISourceLocation sourceLoc = currNode.getSourceLocation(); +// if (null != sourceLoc) { +// Ajde.getDefault().getEditorManager().addViewForSourceLine( +// sourceLoc.getSourceFile().getAbsolutePath(), +// sourceLoc.getLine()); +// } +// } +// } + + } + }); + popup.add(showSourcesItem); + + popup.addSeparator(); + JMenuItem generatePCD = new JMenuItem("Pointcut Wizard (alpha)...", Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.POINTCUT)); + generatePCD.setFont(new java.awt.Font("Dialog", 0, 11)); + generatePCD.addActionListener(new AbstractAction() { + + private static final long serialVersionUID = 1L; + + public void actionPerformed(ActionEvent e) { + Ajde.getDefault().getViewManager().extractAndInsertSignatures(signatures, true); + } + }); + popup.add(generatePCD); + + popup.show(e.getComponent(), e.getX(), e.getY()); + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/BuildConfigPopupMenu.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BuildConfigPopupMenu.java new file mode 100644 index 000000000..7ca7a35fd --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BuildConfigPopupMenu.java @@ -0,0 +1,61 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Iterator; +import java.util.List; + +import javax.swing.AbstractAction; +import javax.swing.Icon; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +import org.aspectj.ajde.Ajde; +import org.aspectj.asm.IProgramElement; + +/** + * Creates a popup menu that displays all the available .lst files. When one + * is selected it runs a full build of files within the selected .lst file + * in a separate thread. + */ +public class BuildConfigPopupMenu extends JPopupMenu { + + private static final long serialVersionUID = -6730132748667530482L; + + public BuildConfigPopupMenu(final AbstractAction action) { + List configFiles = Ajde.getDefault().getBuildConfigManager().getAllBuildConfigFiles(); + for (Iterator it = configFiles.iterator(); it.hasNext(); ) { + final String buildConfig = (String)it.next(); + JMenuItem buildItem = new JMenuItem(buildConfig); + buildItem.setFont(AjdeWidgetStyles.DEFAULT_LABEL_FONT); + buildItem.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(buildConfig); + // A separate thread is required here because the buildProgresssMonitor + // that monitors the build needs to be in a different thread + // to that which is doing the build (swing threading issues) + Ajde.getDefault().runBuildInDifferentThread(buildConfig, true); + action.actionPerformed(e); + } + }); + buildItem.setIcon((Icon)Ajde.getDefault().getIconRegistry().getIcon(IProgramElement.Kind.FILE_LST).getIconResource()); + this.add(buildItem); + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/BuildProgressPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BuildProgressPanel.java new file mode 100644 index 000000000..8b778cd8a --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/BuildProgressPanel.java @@ -0,0 +1,141 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; + +/** + * @author Mik Kersten + */ +public class BuildProgressPanel extends JPanel { + + //private static final long serialVersionUID = -8045879840621749183L; + private static final int MAX_VAL = 100; + //private JDialog dialog = null; + + BorderLayout borderLayout1 = new BorderLayout(); + JPanel cancel_panel = new JPanel(); + JButton cancel_button = new JButton(); + JPanel jPanel2 = new JPanel(); + JLabel progress_label = new JLabel(); + JLabel configFile_label = new JLabel(); + BorderLayout borderLayout3 = new BorderLayout(); + JPanel jPanel1 = new JPanel(); + JProgressBar compile_progressBar = new JProgressBar(); + + private boolean buildIsCancelled = false; + + /** + * @param maxVal the value to which value to which the progress bar will + * count up to (in seconds) + */ + public BuildProgressPanel() { + try { + jbInit(); + compile_progressBar.setMaximum(MAX_VAL); + } catch (Exception e) { + throw new RuntimeException(e.toString()); + } + } + +// public void start() { +// dialog = +// new JDialog(TopManager.INSTANCE.getRootFrame(), "ajc Build Progress", false); +// // progressDialog = new CompileProgressPanel(); +// dialog.setContentPane(this); +// dialog.setSize(500, 110); +// dialog.setLocationRelativeTo(TopManager.INSTANCE.getRootFrame()); +// dialog.setVisible(true); +// } + + public void setProgressText(String text) { + progress_label.setText(" " + text); + } + + public void setConfigFile(String configFile) { + configFile_label.setText(" Build configuration: " + configFile); + } + + /** + * Jumps the progress bar <CODE>newVal</CODE> seconds ahead. + */ + public void setProgressBarVal(int newVal) { + compile_progressBar.setValue(newVal); + } + + public void setProgressBarMax(int maxVal) { + compile_progressBar.setMaximum(maxVal); + } + + public int getProgressBarMax() { + return compile_progressBar.getMaximum(); + } + + /** + * Makes the progress bar move one second ahead. + */ + public void incrementProgressBarVal() { + int newVal = compile_progressBar.getValue() + 1; + compile_progressBar.setValue(newVal); + } + + /** + * Jumps the progress bar to the end. + */ + public void finish() { + compile_progressBar.setValue(compile_progressBar.getMaximum()); + } + + private void jbInit() throws Exception { + this.setLayout(borderLayout1); + cancel_button.setFont(new java.awt.Font("Dialog", 0, 11)); + cancel_button.setText("Cancel"); + cancel_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + cancel_button_actionPerformed(e); + } + }); + progress_label.setFont(new java.awt.Font("Dialog", 0, 11)); + progress_label.setText(""); + jPanel2.setPreferredSize(new Dimension(360, 24)); + jPanel2.setLayout(borderLayout3); + configFile_label.setFont(new java.awt.Font("Dialog", 0, 11)); + configFile_label.setText(""); + compile_progressBar.setPreferredSize(new Dimension(330, 14)); + this.add(cancel_panel, BorderLayout.SOUTH); + cancel_panel.add(cancel_button, null); + this.add(jPanel2, BorderLayout.CENTER); + jPanel2.add(configFile_label, BorderLayout.NORTH); + jPanel2.add(progress_label, BorderLayout.SOUTH); + jPanel2.add(jPanel1, BorderLayout.CENTER); + jPanel1.add(compile_progressBar, null); + } + + void cancel_button_actionPerformed(ActionEvent e) { + buildIsCancelled = true; + } + + public boolean isCancelRequested() { + return buildIsCancelled; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/CompilerMessagesCellRenderer.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/CompilerMessagesCellRenderer.java new file mode 100644 index 000000000..ea681475f --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/CompilerMessagesCellRenderer.java @@ -0,0 +1,81 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.Component; + +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.ListCellRenderer; + +import org.aspectj.ajde.Ajde; +import org.aspectj.bridge.IMessage; +import org.aspectj.util.LangUtil; + +/** + * @author Mik Kersten + */ +public class CompilerMessagesCellRenderer extends JLabel implements ListCellRenderer { + + private static final long serialVersionUID = -4406791252357837712L; + + public Component getListCellRendererComponent( + JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + String label = "<no message>"; + String detail = null; + IMessage.Kind kind = IMessage.ERROR; + if (value instanceof IMessage) { + IMessage cm = (IMessage) value; + label = cm.getMessage(); + if (LangUtil.isEmpty(label)) { + label = cm.getMessage(); + } + kind = cm.getKind(); + Throwable thrown = cm.getThrown(); + if (null != thrown) { + detail = LangUtil.renderException(thrown); + } + } else if (null != value) { + label = value.toString(); + } + setText(label); + if (kind.equals(IMessage.WARNING)) { + setIcon(Ajde.getDefault().getIconRegistry().getWarningIcon()); + } else if (IMessage.ERROR.isSameOrLessThan(kind)) { + setIcon(Ajde.getDefault().getIconRegistry().getErrorIcon()); + } else { + setIcon(Ajde.getDefault().getIconRegistry().getInfoIcon()); + } + if (isSelected) { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + } else { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } + setEnabled(list.isEnabled()); + setFont(list.getFont()); + setOpaque(true); + if (null != detail) { + setToolTipText(detail); + } + return this; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/DefaultBuildProgressMonitor.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/DefaultBuildProgressMonitor.java new file mode 100644 index 000000000..7fab45d91 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/DefaultBuildProgressMonitor.java @@ -0,0 +1,82 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.Frame; + +import javax.swing.JDialog; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.core.IBuildProgressMonitor; + +/** + * This dialog box is open while ajc is compiling the system and displays + * a corresponding progress bar. + * + * @author Mik Kersten + */ +public class DefaultBuildProgressMonitor extends Thread implements IBuildProgressMonitor { + + public static final String PROGRESS_HEADING = "AspectJ Build"; + + private BuildProgressPanel progressDialog = null; + private JDialog dialog = null; + + public DefaultBuildProgressMonitor(Frame parent) { + dialog = new JDialog(parent, PROGRESS_HEADING, false); + progressDialog = new BuildProgressPanel(); + dialog.setContentPane(progressDialog); + dialog.setSize(550, 120); + try { + dialog.setLocationRelativeTo(parent); + } catch (NoSuchMethodError nsme) { + // running on 1.3 + } + } + + /** + * Start the progress monitor. + */ + public void begin() { + progressDialog.setProgressBarVal(0); + progressDialog.setProgressText("starting build..."); + dialog.setLocationRelativeTo(Ajde.getDefault().getRootFrame()); + dialog.setVisible(true); + } + + /** + * Sets the label describing the current progress phase. + */ + public void setProgressText(String text) { + progressDialog.setProgressText(text); + } + + /** + * Jump the progress bar to the end and finish progress monitoring. + */ + public void finish(boolean wasFullBuild) { + progressDialog.finish(); + dialog.dispose(); + } + + public boolean isCancelRequested() { + return progressDialog.isCancelRequested(); + } + + public void setProgress(double percentDone) { + progressDialog.setProgressBarVal((int) (percentDone*progressDialog.getProgressBarMax())); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/ErrorDialog.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/ErrorDialog.java new file mode 100644 index 000000000..582926a92 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/ErrorDialog.java @@ -0,0 +1,105 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.border.Border; + +public class ErrorDialog extends JDialog { + private static final long serialVersionUID = 5646564514289861666L; + JPanel top_panel = new JPanel(); + BorderLayout borderLayout2 = new BorderLayout(); + JPanel button_panel = new JPanel(); + JButton close_button = new JButton(); + JScrollPane jScrollPane1 = new JScrollPane(); + JTextArea stackTrace_textArea = new JTextArea(); + JPanel jPanel1 = new JPanel(); + JLabel error_label1 = new JLabel(); + JLabel error_label2 = new JLabel(); + BorderLayout borderLayout1 = new BorderLayout(); + Border border1; + BorderLayout borderLayout3 = new BorderLayout(); + + public ErrorDialog(Frame owner, String title, Throwable throwable, String message, String details) { + super(owner, title, true); + try { + jbInit(); + String exceptionName = "<unknown exception>"; + if (throwable != null) exceptionName = throwable.getClass().getName(); + this.error_label1.setText("Exception: " + exceptionName); + this.error_label2.setText("If you can't fix it, please submit a bug to http://dev.eclipse.org/bugs"); + this.stackTrace_textArea.setText("Message: " + message + '\n' + "Stack trace: " + details); + this.setSize(420, 330); + this.setLocationRelativeTo(owner); + this.getContentPane().setLayout(borderLayout1); + } + catch(Exception e) { + e.printStackTrace(); + } + } + + private void jbInit() throws Exception { + border1 = BorderFactory.createEmptyBorder(5,5,5,5); + this.getContentPane().setLayout(borderLayout1); + top_panel.setLayout(borderLayout2); + close_button.setFont(new java.awt.Font("Dialog", 0, 11)); + close_button.setText("Close"); + close_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + close_button_actionPerformed(e); + } + }); + top_panel.setBorder(border1); + top_panel.setPreferredSize(new Dimension(400, 290)); + stackTrace_textArea.setFont(new java.awt.Font("Monospaced", 0, 11)); + error_label1.setFont(new java.awt.Font("Dialog", 0, 11)); + error_label1.setFont(new java.awt.Font("Dialog", 0, 11)); + error_label1.setForeground(Color.black); + error_label1.setMaximumSize(new Dimension(400, 16)); + error_label1.setPreferredSize(new Dimension(390, 16)); + error_label1.setText("label1"); + jPanel1.setLayout(borderLayout3); + error_label2.setFont(new java.awt.Font("Dialog", 0, 11)); + error_label2.setMaximumSize(new Dimension(400, 16)); + error_label2.setPreferredSize(new Dimension(390, 16)); + error_label2.setText("label2"); + error_label2.setForeground(Color.black); + jPanel1.setPreferredSize(new Dimension(600, 44)); + this.getContentPane().add(top_panel, BorderLayout.CENTER); + top_panel.add(button_panel, BorderLayout.SOUTH); + button_panel.add(close_button, null); + top_panel.add(jScrollPane1, BorderLayout.CENTER); + top_panel.add(jPanel1, BorderLayout.NORTH); + jPanel1.add(error_label1, BorderLayout.NORTH); + jPanel1.add(error_label2, BorderLayout.CENTER); + jScrollPane1.getViewport().add(stackTrace_textArea, null); + } + + void close_button_actionPerformed(ActionEvent e) { + this.dispose(); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/GoToLineThread.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/GoToLineThread.java new file mode 100644 index 000000000..7b7ae7b68 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/GoToLineThread.java @@ -0,0 +1,84 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + + +package org.aspectj.ajde.ui.swing; + +import javax.swing.SwingUtilities; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.EditorAdapter; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * Used to ensure that a source line has been seeked to. Will repeatedly attempt + * to seek to the line until this has succeeded. + * + * @author Mik Kersten + */ +public class GoToLineThread extends Thread { + private EditorAdapter editorAdapter = null; + + private int lineNumber = 0; + private String fileToSeekTo = ""; + private boolean finished = false; + + public boolean isFinished() { + return finished; + } + + public boolean needsRetry() { + return !this.isAlive() && !finished; + } + + public GoToLineThread(String fileToSeekTo, int lineNumber, EditorAdapter editorAdapter) { + this.lineNumber = lineNumber; + this.fileToSeekTo = fileToSeekTo; + this.editorAdapter = editorAdapter; + } + + public void run() { + + while(true) { + String file = editorAdapter.getCurrFile(); + if (file != null) { + if (file.equals(this.fileToSeekTo)) { + try { + SwingUtilities.invokeAndWait( new Runnable() { + public void run() { + editorAdapter.showSourceLine(lineNumber, true); + } + }); + } catch (Exception e) { + Message msg = new Message("Could not seek to line.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + finished = true; + break; + } + shortPause(); + } + } + } + + private void shortPause() { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage()); + } + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/MultiStructureViewPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/MultiStructureViewPanel.java new file mode 100644 index 000000000..5c44d09ba --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/MultiStructureViewPanel.java @@ -0,0 +1,54 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; + +import javax.swing.JPanel; +import javax.swing.JSplitPane; + +import org.aspectj.ajde.Ajde; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * @author Mik Kersten + */ +public class MultiStructureViewPanel extends JPanel { + + private static final long serialVersionUID = -4409192026967597082L; + JSplitPane views_splitPane; + BorderLayout borderLayout1 = new BorderLayout(); + + public MultiStructureViewPanel(StructureViewPanel topPanel, StructureViewPanel bottomPanel) { + super(); + try { + views_splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel); + jbInit(); + } catch(Exception e) { + Message msg = new Message("Could not initialize GUI.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + private void jbInit() throws Exception { + this.setLayout(borderLayout1); + this.add(views_splitPane, BorderLayout.CENTER); + views_splitPane.setDividerSize(4); + views_splitPane.setDividerLocation(300); + } + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/OptionsFrame.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/OptionsFrame.java new file mode 100644 index 000000000..130183676 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/OptionsFrame.java @@ -0,0 +1,286 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.io.IOException; +import java.util.Date; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.UIManager; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.IconRegistry; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; +import org.aspectj.bridge.Version; + +/** + * UI for setting user-configureable options. + * + * @author Mik Kersten + */ +public class OptionsFrame extends JFrame { + + private static final long serialVersionUID = -859222442871124487L; + + // XXX using \n b/c JTextArea.setLineWrap(true) lineates inside words. + private static final String ABOUT_TEXT = + "\nThe AspectJ compiler and core tools are produced by the\n" + + "AspectJ project.\n\n" + + "This software is distributed under the Eclipse Public License\n" + + "version 1.0, approved by the Open Source Initiative as\n" + + "conforming to the Open Source Definition.\n\n" + + "For support or for more information about the AspectJ\n" + + "project or the license, visit the project home page at\n" + + " http://eclipse.org/aspectj\n\n" + + "If you find a bug (not solved by the documentation in the\n" + + "Development Environment Guide available with this release,\n" + + "any release notes, or the bug database), please submit steps\n" + + "to reproduce the bug (using the IDE component) at:\n" + + " http://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ"; + + private JTabbedPane main_tabbedPane = new JTabbedPane(); + private JPanel button_panel = new JPanel(); + private JButton apply_button = new JButton(); + private JButton cancel_button = new JButton(); + private JButton ok_button = new JButton(); + private TitledBorder titledBorder1; + private TitledBorder titledBorder2; + private TitledBorder titledBorder3; +// private Border border1; + private TitledBorder titledBorder4; + private TitledBorder titledBorder5; +// private Border border2; + private TitledBorder titledBorder6; +// private Box temp_box = Box.createVerticalBox(); +// private Border border3; + private TitledBorder titledBorder7; + private Border border4; + private TitledBorder titledBorder8; + private Border border5; + private TitledBorder titledBorder9; +// private Border border6; + private TitledBorder titledBorder10; +// private ButtonGroup views_buttonGroup = new ButtonGroup(); + private Border border7; + private TitledBorder titledBorder11; + private Border border8; + private TitledBorder titledBorder12; + private JPanel about_panel = new JPanel(); + private BorderLayout borderLayout9 = new BorderLayout(); + JTextArea jTextArea1 = new JTextArea(); + JPanel jPanel1 = new JPanel(); + JLabel version_label = new JLabel(); + JLabel jLabel1 = new JLabel(); + BorderLayout borderLayout1 = new BorderLayout(); + Border border9; + JLabel built_label = new JLabel(); + + public OptionsFrame(IconRegistry icons) { + try { + jbInit(); + + this.setTitle("AJDE Settings"); + this.setIconImage(((ImageIcon)icons.getBrowserOptionsIcon()).getImage()); + this.setSize(500, 500); + this.setLocation(200, 100); + + version_label.setText("Version: " + Version.text); + built_label.setText("Built: " + new Date(Version.getTime()).toString()); + } + catch(Exception e) { + Message msg = new Message("Could not open OptionsFrame.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + /** + * Adds the panel in the second-to-last postion. + */ + public void addOptionsPanel(OptionsPanel panel) { + main_tabbedPane.add(panel, main_tabbedPane.getComponentCount()-1); + try { + panel.loadOptions(); + } catch (IOException e) { + Message msg = new Message("Could not load options.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + public void removeOptionsPanel(OptionsPanel panel) { + main_tabbedPane.remove(panel); + } + + public void showPanel(OptionsPanel panel) { + setVisible(true); + main_tabbedPane.setSelectedComponent(panel); + } +// +// private void loadOptions() { +// try { +// Component[] components = main_tabbedPane.getComponents(); +// for (int i = 0; i < components.length; i++) { +// if (components[i] instanceof OptionsPanel) { +// ((OptionsPanel)components[i]).loadOptions(); +// } +// } +// } catch (IOException ioe) { +// Message msg = new Message("Could not load options.",IMessage.ERROR,ioe,null); +// Ajde.getDefault().getMessageHandler().handleMessage(msg); +// } +// } + + private void saveOptions() { + try { + Component[] components = main_tabbedPane.getComponents(); + for (int i = 0; i < components.length; i++) { + if (components[i] instanceof OptionsPanel) { + ((OptionsPanel)components[i]).saveOptions(); + } + } + } catch (IOException ioe) { + Message msg = new Message("Could not load options.",IMessage.ERROR,ioe,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + private void close() { + this.setVisible(false); + } + + private void apply_button_actionPerformed(ActionEvent e) { + saveOptions(); + } + + private void ok_button_actionPerformed(ActionEvent e) { + saveOptions(); + close(); + } + + private void cancel_button_actionPerformed(ActionEvent e) { + close(); + } + + private void jbInit() throws Exception { + titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)),"Sorting"); + titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Associations (navigeable relations between sturcture nodes)"); + titledBorder3 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)),"Member Filtering (nodes to exclude from view)"); + BorderFactory.createLineBorder(Color.black,2); + titledBorder4 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Compile Options"); + titledBorder5 = new TitledBorder(""); + BorderFactory.createLineBorder(Color.black,2); + titledBorder6 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Run Options"); + BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)); + titledBorder7 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)),"Granularity (all nodes below selected level will be hidden)"); + border4 = BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)); + titledBorder8 = new TitledBorder(border4,"Member Visibility"); + border5 = BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)); + titledBorder9 = new TitledBorder(border5,"Member Modifiers"); + BorderFactory.createEmptyBorder(); + titledBorder10 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)),"Structure View Properties"); + border7 = BorderFactory.createEtchedBorder(Color.white,new Color(156, 156, 158)); + titledBorder11 = new TitledBorder(border7,"Member Kinds"); + border8 = BorderFactory.createEtchedBorder(Color.white,new Color(148, 145, 140)); + titledBorder12 = new TitledBorder(border8,"Build Paths"); + border9 = BorderFactory.createEmptyBorder(6,6,6,6); + jPanel1.setLayout(borderLayout1); + jLabel1.setFont(new java.awt.Font("Dialog", 1, 14)); + jLabel1.setText("AspectJ Development Environment (AJDE)"); + version_label.setFont(new java.awt.Font("Dialog", 1, 12)); + version_label.setText("Version: "); + apply_button.setFont(new java.awt.Font("Dialog", 0, 11)); + apply_button.setMaximumSize(new Dimension(70, 24)); + apply_button.setMinimumSize(new Dimension(63, 24)); + apply_button.setPreferredSize(new Dimension(70, 24)); + apply_button.setText("Apply"); + apply_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + apply_button_actionPerformed(e); + } + }); + cancel_button.setFont(new java.awt.Font("Dialog", 0, 11)); + cancel_button.setMaximumSize(new Dimension(70, 24)); + cancel_button.setMinimumSize(new Dimension(67, 24)); + cancel_button.setPreferredSize(new Dimension(70, 24)); + cancel_button.setText("Cancel"); + cancel_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + cancel_button_actionPerformed(e); + } + }); + ok_button.setFont(new java.awt.Font("Dialog", 0, 11)); + ok_button.setMaximumSize(new Dimension(70, 24)); + ok_button.setMinimumSize(new Dimension(49, 24)); + ok_button.setPreferredSize(new Dimension(70, 24)); + ok_button.setText("OK"); + ok_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + ok_button_actionPerformed(e); + } + }); + main_tabbedPane.setFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder1.setTitle("Ordering (sort order of nodes)"); + titledBorder1.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder2.setTitle("Associations (navigeable relations between structure nodes)"); + titledBorder2.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder3.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder6.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder5.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder4.setTitle("AjCompiler Flags"); + titledBorder4.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder7.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder8.setTitle("Access Modifiers"); + titledBorder8.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder9.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder10.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder11.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + titledBorder12.setTitleFont(new java.awt.Font("Dialog", 0, 11)); + about_panel.setLayout(borderLayout9); + jTextArea1.setBackground(UIManager.getColor("ColorChooser.background")); + jTextArea1.setFont(new java.awt.Font("SansSerif", 0, 12)); + jTextArea1.setEditable(false); + jTextArea1.setText(ABOUT_TEXT); + + about_panel.setBorder(border9); + built_label.setText("Built: "); + built_label.setFont(new java.awt.Font("Dialog", 1, 12)); + main_tabbedPane.add(about_panel, "About AJDE"); + this.getContentPane().add(button_panel, BorderLayout.SOUTH); + button_panel.add(ok_button, null); + button_panel.add(cancel_button, null); + button_panel.add(apply_button, null); + this.getContentPane().add(main_tabbedPane, BorderLayout.CENTER); + about_panel.add(jTextArea1, BorderLayout.CENTER); + about_panel.add(jPanel1, BorderLayout.NORTH); + jPanel1.add(jLabel1, BorderLayout.NORTH); + jPanel1.add(version_label, BorderLayout.CENTER); + jPanel1.add(built_label, BorderLayout.SOUTH); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/OptionsPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/OptionsPanel.java new file mode 100644 index 000000000..e49fc247a --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/OptionsPanel.java @@ -0,0 +1,29 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.io.IOException; + +import javax.swing.JPanel; + +/** + * @author Mik Kersten + */ +public abstract class OptionsPanel extends JPanel { + + public abstract void loadOptions() throws IOException; + + public abstract void saveOptions() throws IOException; +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/PointcutWizard.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/PointcutWizard.java new file mode 100644 index 000000000..ed7235186 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/PointcutWizard.java @@ -0,0 +1,161 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.*; +//import java.awt.event.ActionEvent; +import java.util.*; + +import javax.swing.*; + +import org.aspectj.ajde.ui.*; +//import org.aspectj.asm.IRelationship; + +/** + * @author Mik Kersten + */ +class PointcutWizard extends JFrame { + private static final long serialVersionUID = -9058319919402871975L; +// private BrowserViewPanel typeTreeView = null; +// private java.util.List signatures = null; + + JPanel jPanel1 = new JPanel(); + JPanel jPanel2 = new JPanel(); + JPanel jPanel4 = new JPanel(); + JLabel jLabel1 = new JLabel(); + BorderLayout borderLayout1 = new BorderLayout(); + BorderLayout borderLayout2 = new BorderLayout(); + BorderLayout borderLayout3 = new BorderLayout(); + JLabel jLabel4 = new JLabel(); + JPanel jPanel3 = new JPanel(); + JCheckBox jCheckBox5 = new JCheckBox(); + JCheckBox jCheckBox4 = new JCheckBox(); + JCheckBox jCheckBox3 = new JCheckBox(); + JCheckBox jCheckBox2 = new JCheckBox(); + JCheckBox jCheckBox1 = new JCheckBox(); + JButton cancel_button = new JButton(); + JButton ok_button = new JButton(); + JPanel jPanel5 = new JPanel(); + + public PointcutWizard(java.util.List signatures) { + // this.signatures = signatures; + ArrayList views = new ArrayList(); + views.add(StructureViewProperties.Hierarchy.INHERITANCE); +// typeTreeView = new BrowserViewPanel(AjdeUIManager.getDefault().getIconRegistry(), views, StructureViewProperties.Hierarchy.INHERITANCE); + + throw new RuntimeException("unimplemented, can't get the current file"); + //typeTreeView.updateTree(Ajde.getDefault().getEditorManager().getCurrFile()); +// try { +// jbInit(); +// } +// catch(Exception e) { +// Ajde.getDefault().getErrorHandler().handleError("Could not initialize GUI.", e); +// } +// this.setSize(400, 400); +// this.setIconImage(((ImageIcon)AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.POINTCUT)).getImage()); + } + +// private Map getViewProperties() { +// Map views = new HashMap(); +// GlobalViewProperties INHERITANCE_VIEW = new GlobalViewProperties(StructureViewProperties.Hierarchy.INHERITANCE); +//// INHERITANCE_VIEW.addRelation(IRelationship.Kind.INHERITANCE); +//// views.put(INHERITANCE_VIEW.toString(), INHERITANCE_VIEW); +// return views; +// } +// +// private void jbInit() throws Exception { +// jLabel1.setFont(new java.awt.Font("Dialog", 0, 11)); +// jLabel1.setText("Generate pointcut designator for corresponding joinpoints:"); +// jPanel1.setLayout(borderLayout1); +// jPanel4.setLayout(borderLayout2); +// jPanel2.setLayout(borderLayout3); +// jLabel4.setText("Select the target type that will host the generated pointcut:"); +// jLabel4.setFont(new java.awt.Font("Dialog", 0, 11)); +// jLabel4.setToolTipText(""); +// jPanel3.setMaximumSize(new Dimension(32767, 34)); +// jCheckBox5.setEnabled(false); +// jCheckBox5.setFont(new java.awt.Font("Dialog", 0, 11)); +// jCheckBox5.setSelected(true); +// jCheckBox5.setText("call"); +// jCheckBox4.setEnabled(false); +// jCheckBox4.setFont(new java.awt.Font("Dialog", 0, 11)); +// jCheckBox4.setText("execution"); +// jCheckBox3.setEnabled(false); +// jCheckBox3.setFont(new java.awt.Font("Dialog", 0, 11)); +// jCheckBox3.setText("initialization"); +// jCheckBox2.setEnabled(false); +// jCheckBox2.setFont(new java.awt.Font("Dialog", 0, 11)); +// jCheckBox2.setText("static initialization"); +// jCheckBox1.setEnabled(false); +// jCheckBox1.setFont(new java.awt.Font("Dialog", 0, 11)); +// jCheckBox1.setText("field get/set"); +// cancel_button.setFont(new java.awt.Font("Dialog", 0, 11)); +// cancel_button.setText("Cancel"); +// cancel_button.addActionListener(new java.awt.event.ActionListener() { +// public void actionPerformed(ActionEvent e) { +// cancel_button_actionPerformed(e); +// } +// }); +// ok_button.setText("OK"); +// ok_button.addActionListener(new java.awt.event.ActionListener() { +// public void actionPerformed(ActionEvent e) { +// ok_button_actionPerformed(e); +// } +// }); +// ok_button.setFont(new java.awt.Font("Dialog", 0, 11)); +// this.setTitle("Pointcut Wizard"); +// this.getContentPane().add(jPanel1, BorderLayout.CENTER); +// jPanel1.add(jPanel4, BorderLayout.NORTH); +// jPanel4.add(jLabel1, BorderLayout.NORTH); +// jPanel4.add(jPanel3, BorderLayout.CENTER); +// jPanel3.add(jCheckBox5, null); +// jPanel3.add(jCheckBox4, null); +// jPanel3.add(jCheckBox3, null); +// jPanel3.add(jCheckBox2, null); +// jPanel3.add(jCheckBox1, null); +// jPanel1.add(jPanel2, BorderLayout.CENTER); +// jPanel2.add(jLabel4, BorderLayout.NORTH); +// jPanel2.add(typeTreeView, BorderLayout.CENTER); +// jPanel1.add(jPanel5, BorderLayout.SOUTH); +// jPanel5.add(ok_button, null); +// jPanel5.add(cancel_button, null); +// } + +// private void ok_button_actionPerformed(ActionEvent e) { +// throw new RuntimeException("unimplemented, can't paste"); +//// Ajde.getDefault().getEditorManager().pasteToCaretPos(generatePcd()); +//// this.dispose(); +// } +// +// private void cancel_button_actionPerformed(ActionEvent e) { +// this.dispose(); +// } +// +// private String generatePcd() { +// String pcd = "\n\n" + +// " pointcut temp(): \n"; +// for (Iterator it = signatures.iterator(); it.hasNext(); ) { +// pcd += " call(* " + it.next() + ")"; +// if (it.hasNext()) { +// pcd += " ||"; +// } else { +// pcd += ";"; +// } +// pcd += "\n"; +// } +// return pcd; +// } +} + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java new file mode 100644 index 000000000..b12698d5e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java @@ -0,0 +1,252 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.SystemColor; +import java.awt.event.ActionEvent; +import java.io.File; +import java.util.ArrayList; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.BevelBorder; +import javax.swing.border.Border; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.StructureView; +import org.aspectj.ajde.ui.StructureViewProperties; +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.IHierarchyListener; +import org.aspectj.asm.IProgramElement; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +public class SimpleStructureViewToolPanel extends JPanel { + + private static final long serialVersionUID = -7573973278642540506L; + private final StructureView currentView; + private final JButton separator_button = new JButton(); + private boolean hideNonAJEnabled = false; + private boolean hideAssociationsEnabled = false; + private boolean sortEnabled = false; + + Border border1; + Border border2; + JButton structureView_button = new JButton(); + JPanel label_panel = new JPanel(); + JLabel currConfig_field = new JLabel(); + JPanel spacer_panel = new JPanel(); + JPanel jPanel2 = new JPanel(); + JButton forward_button = new JButton(); + JPanel navigation_panel = new JPanel(); + JButton back_button = new JButton(); + BorderLayout borderLayout1 = new BorderLayout(); + JPanel buttons_panel = new JPanel(); + BorderLayout borderLayout2 = new BorderLayout(); + BorderLayout borderLayout3 = new BorderLayout(); + BorderLayout borderLayout4 = new BorderLayout(); + + public final IHierarchyListener MODEL_LISTENER = new IHierarchyListener() { + public void elementsUpdated(IHierarchy model) { + String path = Ajde.getDefault().getBuildConfigManager().getActiveConfigFile(); + String fileName = "<no active config>"; + if (path != null) + fileName = new File(path).getName(); + updateCurrConfigLabel(fileName); + } + }; + + JButton hideNonAJ_button = new JButton(); + JPanel navigation_panel1 = new JPanel(); + JButton hideAssociations_button = new JButton(); + BorderLayout borderLayout5 = new BorderLayout(); + JButton sort_button = new JButton(); + + public SimpleStructureViewToolPanel(StructureView currentView) { + this.currentView = currentView; + Ajde.getDefault().getModel().addListener(MODEL_LISTENER); + try { + jbInit(); + } catch (Exception e) { + Message msg = new Message("Could not initialize GUI.", IMessage.ERROR, e, null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + updateCurrConfigLabel("<no active config>"); + } + + private void updateCurrConfigLabel(String text) { + currConfig_field.setText(" File View (" + text + ")"); + } + + private void jbInit() throws Exception { + border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.white, Color.white, new Color(156, 156, 158), + new Color(109, 109, 110)); + border2 = BorderFactory.createEmptyBorder(0, 1, 0, 0); + + separator_button.setPreferredSize(new Dimension(2, 16)); + separator_button.setMinimumSize(new Dimension(2, 16)); + separator_button.setEnabled(false); + separator_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + separator_button.setMaximumSize(new Dimension(2, 16)); + + structureView_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + structureView_button_actionPerformed(e); + } + }); + structureView_button.setIcon(Ajde.getDefault().getIconRegistry().getStructureViewIcon()); + structureView_button.setBorder(border2); + structureView_button.setToolTipText("Navigate back"); + structureView_button.setPreferredSize(new Dimension(20, 20)); + structureView_button.setMinimumSize(new Dimension(20, 20)); + structureView_button.setMaximumSize(new Dimension(24, 20)); + currConfig_field.setBackground(SystemColor.control); + currConfig_field.setFont(new java.awt.Font("SansSerif", 0, 11)); + currConfig_field.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + // currConfig_field.setEditable(false); + currConfig_field.setText(" "); + + forward_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + forward_button_actionPerformed(e); + } + }); + forward_button.setIcon(Ajde.getDefault().getIconRegistry().getForwardIcon()); + forward_button.setToolTipText("Navigate forward"); + forward_button.setPreferredSize(new Dimension(20, 20)); + forward_button.setMinimumSize(new Dimension(20, 20)); + forward_button.setMaximumSize(new Dimension(24, 20)); + forward_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + navigation_panel.setLayout(borderLayout1); + back_button.setMaximumSize(new Dimension(24, 20)); + back_button.setMinimumSize(new Dimension(20, 20)); + back_button.setPreferredSize(new Dimension(20, 20)); + back_button.setToolTipText("Navigate back"); + back_button.setIcon(Ajde.getDefault().getIconRegistry().getBackIcon()); + back_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + back_button_actionPerformed(e); + } + }); + back_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + this.setLayout(borderLayout2); + buttons_panel.setLayout(borderLayout3); + label_panel.setLayout(borderLayout4); + hideNonAJ_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + hideNonAJ_button.setMaximumSize(new Dimension(24, 20)); + hideNonAJ_button.setMinimumSize(new Dimension(20, 20)); + hideNonAJ_button.setPreferredSize(new Dimension(20, 20)); + hideNonAJ_button.setToolTipText("Hide non-AspectJ members"); + hideNonAJ_button.setIcon(Ajde.getDefault().getIconRegistry().getHideNonAJIcon()); + hideNonAJ_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + hideNonAJ_button_actionPerformed(e); + } + }); + navigation_panel1.setLayout(borderLayout5); + hideAssociations_button.setMaximumSize(new Dimension(24, 20)); + hideAssociations_button.setMinimumSize(new Dimension(20, 20)); + hideAssociations_button.setPreferredSize(new Dimension(20, 20)); + hideAssociations_button.setToolTipText("Hide associations"); + hideAssociations_button.setIcon(Ajde.getDefault().getIconRegistry().getHideAssociationsIcon()); + hideAssociations_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + hideAssociations_button_actionPerformed(e); + } + }); + hideAssociations_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + sort_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + sort_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + sort_button_actionPerformed(e); + } + }); + sort_button.setIcon(Ajde.getDefault().getIconRegistry().getOrderIcon()); + sort_button.setToolTipText("Sort member"); + sort_button.setPreferredSize(new Dimension(20, 20)); + sort_button.setMinimumSize(new Dimension(20, 20)); + sort_button.setMaximumSize(new Dimension(24, 20)); + label_panel.add(currConfig_field, BorderLayout.CENTER); + // label_panel.add(structureView_button, BorderLayout.WEST); + this.add(spacer_panel, BorderLayout.CENTER); + this.add(buttons_panel, BorderLayout.EAST); + buttons_panel.add(navigation_panel, BorderLayout.CENTER); + navigation_panel.add(back_button, BorderLayout.CENTER); + navigation_panel.add(forward_button, BorderLayout.EAST); + navigation_panel.add(jPanel2, BorderLayout.WEST); + buttons_panel.add(navigation_panel1, BorderLayout.WEST); + navigation_panel1.add(hideAssociations_button, BorderLayout.EAST); + navigation_panel1.add(hideNonAJ_button, BorderLayout.CENTER); + navigation_panel1.add(sort_button, BorderLayout.WEST); + this.add(label_panel, BorderLayout.WEST); + + } + + private void forward_button_actionPerformed(ActionEvent e) { + Ajde.getDefault().getStructureViewManager().fireNavigateForwardAction(currentView); + } + + private void back_button_actionPerformed(ActionEvent e) { + Ajde.getDefault().getStructureViewManager().fireNavigateBackAction(currentView); + } + + void structureView_button_actionPerformed(ActionEvent e) { + + } + + private void hideNonAJ_button_actionPerformed(ActionEvent e) { + if (hideNonAJEnabled) { + hideNonAJ_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + hideNonAJEnabled = false; + currentView.getViewProperties().setFilteredMemberKinds(new ArrayList()); + } else { + hideNonAJ_button.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); + hideNonAJEnabled = true; + currentView.getViewProperties().setFilteredMemberKinds(IProgramElement.Kind.getNonAJMemberKinds()); + } + Ajde.getDefault().getStructureViewManager().refreshView(currentView); + } + + private void hideAssociations_button_actionPerformed(ActionEvent e) { + if (hideAssociationsEnabled) { + hideAssociations_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + hideAssociationsEnabled = false; + currentView.getViewProperties().setRelations(Ajde.getDefault().getStructureViewManager().getAvailableRelations()); + } else { + hideAssociations_button.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); + hideAssociationsEnabled = true; + currentView.getViewProperties().setRelations(new ArrayList()); + } + Ajde.getDefault().getStructureViewManager().refreshView(currentView); + } + + private void sort_button_actionPerformed(ActionEvent e) { + if (sortEnabled) { + sort_button.setBorder(AjdeWidgetStyles.DEFAULT_BORDER); + sortEnabled = false; + currentView.getViewProperties().setSorting(StructureViewProperties.Sorting.DECLARATIONAL); + } else { + sort_button.setBorder(AjdeWidgetStyles.LOWERED_BEVEL_BORDER); + sortEnabled = true; + currentView.getViewProperties().setSorting(StructureViewProperties.Sorting.ALPHABETICAL); + } + Ajde.getDefault().getStructureViewManager().refreshView(currentView); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureTree.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureTree.java new file mode 100644 index 000000000..af4cd16e2 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureTree.java @@ -0,0 +1,62 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.Font; + +import javax.swing.JTree; + +import org.aspectj.ajde.Ajde; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * @author Mik Kersten + */ +class StructureTree extends JTree { + + private static final long serialVersionUID = -5599178058976534562L; + + public static final Font DEFAULT_FONT = new java.awt.Font("Dialog", 0, 11); + + private String rootFilePath = null; + + public StructureTree() { + try { + jbInit(); + } + catch(Exception e) { + Message msg = new Message("Could not initialize GUI.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + public void setRootFilePath(String rootFilePath) { + this.rootFilePath = rootFilePath; + } + + public String getRootFilePath() { + return rootFilePath; + } + + private void jbInit() throws Exception { + this.setFont(DEFAULT_FONT); + } + + public int getToggleClickCount() { + return 1; + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureTreeManager.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureTreeManager.java new file mode 100644 index 000000000..474ba1f60 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureTreeManager.java @@ -0,0 +1,440 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + +package org.aspectj.ajde.ui.swing; + +import java.awt.event.MouseListener; +import java.util.ArrayList; + +import javax.swing.SwingUtilities; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.AbstractIcon; +import org.aspectj.ajde.ui.GlobalStructureView; +import org.aspectj.ajde.ui.IStructureViewNode; +import org.aspectj.ajde.ui.StructureView; +import org.aspectj.ajde.ui.StructureViewProperties; +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.IProgramElement; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * @author Mik Kersten + */ +class StructureTreeManager { + + private StructureTree structureTree; + private SwingTreeViewNodeRenderer cellRenderer = null; + private TreeSelectionListener treeListener = null; + + private final StructureTreeModel NO_STRUCTURE_MODEL = new StructureTreeModel(new SwingTreeViewNode(IHierarchy.NO_STRUCTURE, + new AbstractIcon(null), new ArrayList())); + + /** + * @todo should probably avoid that MouseListener cast + */ + public StructureTreeManager() { + structureTree = new StructureTree(); + structureTree.setModel(NO_STRUCTURE_MODEL); + cellRenderer = new SwingTreeViewNodeRenderer(); + structureTree.setCellRenderer(cellRenderer); + // if (fileView) { + treeListener = new StructureViewTreeListener(structureTree); + // } else { + // treeListener = new BrowserViewTreeListener(structureTree); + // } + structureTree.addTreeSelectionListener(treeListener); + structureTree.addMouseListener((MouseListener) treeListener); + } + + public void highlightNode(IProgramElement node) { + highlightNode((SwingTreeViewNode) structureTree.getModel().getRoot(), node); + } + + public IProgramElement getSelectedIProgramElement() { + return (IProgramElement) ((SwingTreeViewNode) structureTree.getLastSelectedPathComponent()).getUserObject(); + } + + public void scrollToHighlightedNode() { + structureTree.scrollPathToVisible(structureTree.getSelectionPath()); + } + + private void highlightNode(SwingTreeViewNode parent, IProgramElement node) { + for (int i = 0; i < parent.getChildCount(); i++) { + SwingTreeViewNode currNode = (SwingTreeViewNode) parent.getChildAt(i); + IProgramElement sNode = currNode.getStructureNode(); + if (sNode != null && sNode.equals(node) && currNode.getKind() != IStructureViewNode.Kind.LINK) { + TreePath path = new TreePath(currNode.getPath()); + structureTree.setSelectionPath(path); + int currRow = structureTree.getRowForPath(path); + structureTree.expandRow(currRow); + structureTree.scrollRowToVisible(currRow); + } else { + highlightNode(currNode, node); + } + } + } + + // public void updateTree(StructureView structureView) { + // displayTree(structureView, 10); + // } + // + // public void updateTree(GlobalStructureView structureView) { + // displayTree(structureView, depth); + // } + + public void updateTree(final StructureView structureView) { + if (structureView == null) + return; + Runnable update = new Runnable() { + public void run() { + structureTree.removeAll(); + // SwingTreeViewNode currNode; + if (structureView.getRootNode() == null) { + structureTree.setModel(NO_STRUCTURE_MODEL); + } else { + structureTree.setModel(new StructureTreeModel((SwingTreeViewNode) structureView.getRootNode())); + } + + if (structureView instanceof GlobalStructureView) { + GlobalStructureView view = (GlobalStructureView) structureView; + if (view.getGlobalViewProperties().getHierarchy() == StructureViewProperties.Hierarchy.DECLARATION) { + expandTreeToFiles(); + } else { + expandTree(15); + } + } else { + expandTree(10); + } + + } + }; + + if (SwingUtilities.isEventDispatchThread()) { + update.run(); + } else { + try { + SwingUtilities.invokeAndWait(update); + } catch (Exception e) { + Message msg = new Message("Could not update tree.", IMessage.ERROR, e, null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + } + + StructureTree getStructureTree() { + return structureTree; + } + + private void expandTreeToFiles() { + for (int i = 0; i < structureTree.getRowCount(); i++) { + TreePath path = structureTree.getPathForRow(i); + SwingTreeViewNode node = (SwingTreeViewNode) path.getLastPathComponent(); + if (node.getUserObject() instanceof IProgramElement) { + IProgramElement pNode = (IProgramElement) node.getUserObject(); + IProgramElement.Kind kind = pNode.getKind(); + if (kind == IProgramElement.Kind.PROJECT || kind == IProgramElement.Kind.PACKAGE) { + structureTree.expandPath(path); + } else { + structureTree.collapsePath(path); + } + } else { + structureTree.collapsePath(path); + } + } + structureTree.expandPath(structureTree.getPathForRow(0)); + } + + private void expandTree(int depth) { + for (int i = 0; i < structureTree.getRowCount(); i++) { + TreePath path = structureTree.getPathForRow(i); + SwingTreeViewNode node = (SwingTreeViewNode) path.getLastPathComponent(); + if (path.getPath().length - 1 > depth || node.getKind() == IStructureViewNode.Kind.RELATIONSHIP) { + structureTree.collapsePath(path); + } else { + structureTree.expandPath(path); + } + } + structureTree.expandPath(structureTree.getPathForRow(0)); + } + + private static class StructureTreeModel extends DefaultTreeModel { + + private static final long serialVersionUID = 1L; + + public StructureTreeModel(TreeNode newRoot) { + super(newRoot); + } + + public void valueForPathChanged(TreePath path, Object newValue) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); + nodeChanged(node); + } + } +} + +// /** +// * @param node if null assume root +// */ +// public void navigationAction(ProgramElementNode node, boolean followedLink, boolean forward) { +// if (node == null) { +// structureTree.setSelectionRow(0); +// structureTree.scrollRowToVisible(0); +// } else if (node.getSourceLocation().getSourceFilePath() != null) { +// final String fileName = node.getSourceLocation().getSourceFilePath(); +// final int lineNumber = node.getSourceLocation().getLineNumber(); +// if (fileName != null && lineNumber > 0) { +// Runnable update = new Runnable() { +// public void run() { +// Ajde.getDefault().getEditorManager().showSourceLine(fileName, lineNumber, true); +// } +// }; +// +// if (SwingUtilities.isEventDispatchThread()) { +// update.run(); +// } else { +// try { +// SwingUtilities.invokeAndWait(update); +// } catch (Exception ee) { +// +// } +// } +// } +// if (followedLink) { +// highlightNode((SwingTreeViewNode)structureTree.getModel().getRoot(), node); +// } +// } +// } + +// if (node instanceof ProgramElementNode) { +// ProgramElementNode lexicalNode = (ProgramElementNode)node; +// setIcon(getProgramElementNodeIcon(lexicalNode)); +// } else if (node instanceof RelationNode) { +// RelationNode relationNode = (RelationNode)node; +// +// setIcon(icons.getAssociationSwingIcon(relationNode.getRelation())); +// this.setFont(new Font(this.getFont().getName(), Font.ITALIC, this.getFont().getSize())); +// +// } else if (node instanceof LinkNode) { +// LinkNode link = (LinkNode)node; +// setIcon(getProgramElementNodeIcon(link.getProgramElementNode())); +// } else { +// if (node != null && ProgramElementNode.Kind.PACKAGE.equals(node.getKind())) { +// setIcon(icons.getStructureSwingIcon(ProgramElementNode.Kind.PACKAGE)); +// } else if (node != null && ProgramElementNode.Kind.PROJECT.equals(node.getKind())) { +// setIcon(icons.getStructureSwingIcon(ProgramElementNode.Kind.PROJECT)); +// } else if (node != null && ProgramElementNode.Kind.FILE.equals(node.getKind())) { +// setIcon(icons.getStructureSwingIcon(ProgramElementNode.Kind.CLASS)); +// } else { +// setIcon(null); +// } +// } + +// void updateTree(int depth, GlobalViewProperties properties) { +// this.hierarchy = properties.getHierarchy(); +// displayTree(depth, null); +// } +// +// void updateTree(String filePath, int depth, GlobalViewProperties properties) { +// this.hierarchy = properties.getHierarchy(); +// if (filePath == null || filePath.equals("")) { +// structureTree.setModel(NO_FILE_SELECTED_MODEL); +// } else { +// structureTree.setRootFilePath(filePath); +// displayTree(depth, filePath); +// } +// } + +// int accessibility = 0; +// if (pNode.getAccessibility().contains(ProgramElementNode.Accessibility.PUBLIC)) { +// accessibility = 1; +// } else if (pNode.getAccessibility().contains(ProgramElementNode.Accessibility.PROTECTED)) { +// accessibility = 2; +// } else if (pNode.getAccessibility().contains(ProgramElementNode.Accessibility.PRIVATE)) { +// accessibility = 3; +// } else if (pNode.getAccessibility().contains(ProgramElementNode.Accessibility.PRIVILEGED)) { +// accessibility = 3; +// } +// +// if (pNode == null || pNode.getKind() == null) { +// return null; +// } else if (ProgramElementNode.Kind.PROJECT.equals(pNode.getKind())) { +// return icons.getStructureSwingIcon(ProgramElementNode.Kind.PROJECT); +// } else if (ProgramElementNode.Kind.PACKAGE.equals(pNode.getKind())) { +// return icons.getStructureSwingIcon(ProgramElementNode.Kind.PACKAGE); +// } else if (ProgramElementNode.Kind.FILE.equals(pNode.getKind())) { +// return icons.getStructureSwingIcon(ProgramElementNode.Kind.CLASS); +// } else if (ProgramElementNode.Kind.CLASS.equals(pNode.getKind())) { +// switch (accessibility) { +// case 1: return icons.getClassPublicIcon(); +// case 2: return icons.getClassProtectedIcon(); +// case 3: return icons.getClassPrivateIcon(); +// default: return icons.getClassPackageIcon(); +// } +// } else if (ProgramElementNode.Kind.INTERFACE.equals(pNode.getKind())) { +// switch (accessibility) { +// case 1: return icons.getInterfacePublicIcon(); +// case 2: return icons.getInterfaceProtectedIcon(); +// case 3: return icons.getInterfacePrivateIcon(); +// default: return icons.getInterfacePackageIcon(); +// } +// } else if (ProgramElementNode.Kind.ASPECT.equals(pNode.getKind())) { +// switch (accessibility) { +// case 1: return icons.getAspectPublicIcon(); +// case 2: return icons.getAspectProtectedIcon(); +// case 3: return icons.getAspectPrivateIcon(); +// case 4: return icons.getAspectPrivilegedIcon(); +// default: return icons.getAspectPackageIcon(); +// } +// } else if (ProgramElementNode.Kind.METHOD.equals(pNode.getKind()) +// || ProgramElementNode.Kind.INITIALIZER.equals(pNode.getKind()) +// || ProgramElementNode.Kind.CONSTRUCTOR.equals(pNode.getKind())) { +// switch (accessibility) { +// case 1: return icons.getMethodPublicIcon(); +// case 2: return icons.getMethodProtectedIcon(); +// case 3: return icons.getMethodPrivateIcon(); +// default: return icons.getMethodPackageIcon(); +// } +// } else if (ProgramElementNode.Kind.FIELD.equals(pNode.getKind())) { +// switch (accessibility) { +// case 1: return icons.getFieldPublicIcon(); +// case 2: return icons.getFieldProtectedIcon(); +// case 3: return icons.getFieldPrivateIcon(); +// default: return icons.getFieldPackageIcon(); +// } +// } else if (ProgramElementNode.Kind.INTRODUCTION.equals(pNode.getKind())) { +// switch (accessibility) { +// case 1: return icons.getIntroductionPublicIcon(); +// case 2: return icons.getIntroductionProtectedIcon(); +// case 3: return icons.getIntroductionPrivateIcon(); +// default: return icons.getIntroductionPackageIcon(); +// } +// } else if (ProgramElementNode.Kind.POINTCUT.equals(pNode.getKind())) { +// switch (accessibility) { +// case 1: return icons.getJoinpointPublicIcon(); +// case 2: return icons.getJoinpointProtectedIcon(); +// case 3: return icons.getJoinpointPrivateIcon(); +// default: return icons.getJoinpointPackageIcon(); +// } +// } else if (ProgramElementNode.Kind.ADVICE.equals(pNode.getKind())) { +// return icons.getAdviceIcon(); +// } else if (ProgramElementNode.Kind.DECLARE_PARENTS.equals(pNode.getKind())) { +// return icons.getDeclareParentsIcon(); +// } else if (ProgramElementNode.Kind.DECLARE_ERROR.equals(pNode.getKind())) { +// return icons.getDeclareErrorIcon(); +// } else if (ProgramElementNode.Kind.DECLARE_WARNING.equals(pNode.getKind())) { +// return icons.getDeclareWarningIcon(); +// } else if (ProgramElementNode.Kind.DECLARE_SOFT.equals(pNode.getKind())) { +// return icons.getDeclareSoftIcon(); +// } else if (ProgramElementNode.Kind.CODE.equals(pNode.getKind())) { +// return icons.getCodeIcon(); +// } else { +// return null; +// } + +// +// if (relationNode.getKind().equals(org.aspectj.asm.associations.Advice.NAME) || +// relationNode.getKind().equals(org.aspectj.asm.associations.Introduction.NAME)) { +// if (relationNode.getRelation().getBackNavigationName().equals(relationNode.getName()) ){ +// setIcon(icons.getRelationAdviceBackIcon()); +// } else { +// setIcon(icons.getAssociationSwingIcon(relationNode.getRelation())); +// setIcon(icons.getRelationAdviceForwardIcon()); +// } +// } else if (relationNode.getKind().equals(org.aspectj.asm.associations.Inheritance.NAME)) { +// if (relationNode.getRelation().getBackNavigationName().equals(relationNode.getName()) ){ +// setIcon(icons.getRelationInheritanceBackIcon()); +// } else { +// setIcon(icons.getRelationInheritanceForwardIcon()); +// } +// } else { +// if (relationNode.getRelation().getBackNavigationName().equals(relationNode.getName()) ){ +// setIcon(icons.getRelationReferenceBackIcon()); +// } else { +// setIcon(icons.getRelationReferenceForwardIcon()); +// } +// } + +// public ProgramElementNode getRootProgramElementNode() { +// IProgramElement node = (IProgramElement)((SwingTreeViewNode)structureTree.getModel().getRoot()).getUserObject(); +// if (node instanceof ProgramElementNode) { +// return (ProgramElementNode)node; +// } else { +// return null; +// } +// } + +// /** +// * @todo HACK: this is a workaround and can break +// */ +// private static ProgramElementNode mapResult = null; +// private ProgramElementNode getNodeForLink(LinkNode node, IProgramElement rootNode) { +// ProgramElementNode result = null; +// if (rootNode instanceof ProgramElementNode && +// ((ProgramElementNode)rootNode).getName().equals(node.getProgramElementNode().getName())) { +// mapResult = (ProgramElementNode)rootNode; +// } else { +// ProgramElementNode linkedNode = node.getProgramElementNode(); +// for (Iterator it = rootNode.getChildren().iterator(); it.hasNext(); ) { +// IProgramElement child = (IProgramElement)it.next(); +// getNodeForLink(node, child); +// } +// } +// return mapResult; +// } + +// private void sortNodes(List nodes) { +// if (sortNodes) { +// Collections.sort(nodes, IProgramElementComparator); +// } +// } + +// private class IProgramElementComparator implements Comparator { +// public int compare(Object o1, Object o2) { +// IProgramElement t1 = (IProgramElement) ((SwingTreeViewNode) o1).getUserObject(); +// IProgramElement t2 = (IProgramElement) ((SwingTreeViewNode) o2).getUserObject(); +// if (t1 instanceof ProgramElementNode && t2 instanceof ProgramElementNode) { +// ProgramElementNode p1 = (ProgramElementNode) t1; +// ProgramElementNode p2 = (ProgramElementNode) t2; +// return p1.getName().compareTo(p2.getName()); +// } else { +// return 0; +// } +// } +// } + +// private class StructureViewNodeAdapter extends DefaultMutableTreeNode { +// +// private StructureViewNode nodeInfo = null; +// +// public StructureViewNodeAdapter(StructureViewNode nodeInfo) { +// super(nodeInfo, true); +// this.nodeInfo = nodeInfo; +// } +// +// public String toString() { +// if (nodeInfo != null) { +// return nodeInfo.toString(); +// } else { +// return ""; +// } +// } +// } + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureViewPanel.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureViewPanel.java new file mode 100644 index 000000000..c1435051a --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureViewPanel.java @@ -0,0 +1,135 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.util.Iterator; + +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.border.BevelBorder; +import javax.swing.border.Border; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.FileStructureView; +import org.aspectj.ajde.ui.IStructureViewNode; +import org.aspectj.ajde.ui.StructureView; +import org.aspectj.ajde.ui.StructureViewRenderer; +import org.aspectj.asm.IProgramElement; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * Represents the configuration of a structure view of the system, rendered + * by the <CODE>StructureTreeManager</CODE>. + * + * @author Mik Kersten + */ +public class StructureViewPanel extends JPanel implements StructureViewRenderer { + + private static final long serialVersionUID = 7549744200612883786L; + protected StructureTreeManager treeManager = new StructureTreeManager(); + protected StructureView currentView = null; +// private java.util.List structureViews = null; + + protected Border border1; + protected Border border2; + JScrollPane tree_ScrollPane = new JScrollPane(); + JPanel structureToolBar_panel = null; + BorderLayout borderLayout1 = new BorderLayout(); + + public StructureViewPanel(FileStructureView structureView) { + currentView = structureView; + initView(structureView); + structureToolBar_panel = new SimpleStructureViewToolPanel(currentView); + init(); + } + + public StructureViewPanel(java.util.List structureViews) { +// this.structureViews = structureViews; + + for (Iterator it = structureViews.iterator(); it.hasNext(); ) { + initView((StructureView)it.next()); + } + currentView = (StructureView)structureViews.get(0); + structureToolBar_panel = new BrowserStructureViewToolPanel(structureViews, currentView, this); + init(); + } + + private void init() { + try { + jbInit(); + } catch (Exception e) { + Message msg = new Message("Could not initialize view panel.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + updateView(currentView); + } + + public void setCurrentView(StructureView view) { + currentView = view; + treeManager.updateTree(view); + } + + public void updateView(StructureView structureView) { + if (structureView == currentView) { + treeManager.updateTree(structureView); + } + } + + private void initView(StructureView view) { + view.setRenderer(this); + } + + public void setActiveNode(IStructureViewNode node) { + setActiveNode(node, 0); + } + + public void setActiveNode(IStructureViewNode node, int lineOffset) { + if (node == null) return; +// if (!(node.getStructureNode() instanceof IProgramElement)) return; + IProgramElement pNode = node.getStructureNode(); + treeManager.highlightNode(pNode); + if (pNode.getSourceLocation() != null) { + Ajde.getDefault().getEditorAdapter().showSourceLine( + pNode.getSourceLocation().getSourceFile().getAbsolutePath(), + pNode.getSourceLocation().getLine() + lineOffset, + true + ); + } + } + + public void highlightActiveNode() { + if (currentView.getActiveNode() == null) return; + IProgramElement node = currentView.getActiveNode().getStructureNode(); + if (node!=null) { + treeManager.highlightNode(node); + } + } + + protected void jbInit() { + border1 = BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(156, 156, 158),new Color(109, 109, 110)); + border2 = BorderFactory.createEmptyBorder(0,1,0,0); + + this.setLayout(borderLayout1); + this.add(tree_ScrollPane, BorderLayout.CENTER); + this.add(structureToolBar_panel, BorderLayout.NORTH); + + tree_ScrollPane.getViewport().add(treeManager.getStructureTree(), null); + } +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureViewTreeListener.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureViewTreeListener.java new file mode 100644 index 000000000..589762fef --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/StructureViewTreeListener.java @@ -0,0 +1,65 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.IStructureViewNode; + +/** + * @author Mik Kersten + */ +class StructureViewTreeListener implements TreeSelectionListener, MouseListener { + private StructureTree tree; + private SwingTreeViewNode lastSelectedNode = null; + + public StructureViewTreeListener(StructureTree tree) { + this.tree = tree; + } + + public void valueChanged(TreeSelectionEvent e) { } + + public void mouseEntered(MouseEvent e) { } + + public void mouseExited(MouseEvent e) { } + + public void mousePressed(MouseEvent e) { } + + public void mouseReleased(MouseEvent e) { } + + public void mouseClicked(MouseEvent e) { + navigate(e); + } + + public void navigate(MouseEvent e) { + SwingTreeViewNode treeNode = (SwingTreeViewNode)tree.getLastSelectedPathComponent(); + if (treeNode == null || lastSelectedNode == treeNode) return; + lastSelectedNode = treeNode; + + //if (e.getClickCount() == 2) { + Ajde.getDefault().getStructureViewManager().fireNavigationAction( + treeNode.getStructureNode(), + treeNode.getKind() == IStructureViewNode.Kind.LINK + ); + //} + } +} + + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java new file mode 100644 index 000000000..253ea359e --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java @@ -0,0 +1,122 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.util.*; + +import javax.swing.tree.DefaultMutableTreeNode; + +import org.aspectj.ajde.ui.*; +//import org.aspectj.ajde.ui.IStructureViewNode.Kind; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class SwingTreeViewNode extends DefaultMutableTreeNode implements IStructureViewNode { + + private static final long serialVersionUID = 4957761341510335532L; + private String relationshipName; + private IProgramElement programElement; + private AbstractIcon icon; + private IStructureViewNode.Kind kind; + + /** + * Create a declaration node. + */ + public SwingTreeViewNode(IProgramElement programElement, AbstractIcon icon, List children) { + super(programElement, true); + this.programElement = programElement; + this.icon = icon; + this.kind = Kind.DECLARATION; + + if (children != null) { + for (Iterator it = children.iterator(); it.hasNext(); ) { + SwingTreeViewNode child = (SwingTreeViewNode)it.next(); + if (StructureViewNodeFactory.acceptNode(programElement, child.getStructureNode())) { + super.add(child); + } + } + } + } + + /** + * Create a relationship node. + */ + public SwingTreeViewNode(IRelationship relationship, AbstractIcon icon) { + super(null, true); + this.icon = icon; + this.kind = Kind.RELATIONSHIP; + this.relationshipName = relationship.getName(); + } + + /** + * Create a link. + */ + public SwingTreeViewNode(IProgramElement programElement, AbstractIcon icon) { + super(programElement, false); + this.programElement = programElement; + this.kind = Kind.LINK; + this.icon = icon; + } + + public IProgramElement getStructureNode() { + return programElement; + } + + public AbstractIcon getIcon() { + return icon; + } + + public void add(IStructureViewNode child) { + super.add((DefaultMutableTreeNode)child); + } + + public void add(IStructureViewNode child, int position) { + super.insert((DefaultMutableTreeNode)child, position); + } + + public void remove(IStructureViewNode child) { + super.remove((DefaultMutableTreeNode)child); + } + + public List getChildren() { + if (children == null) { + return new ArrayList(); + } else { + return children; + } + } + + public Kind getKind() { + return kind; + } + + public String getRelationshipName() { + return relationshipName; + } + + public String toString() { + if (kind == IStructureViewNode.Kind.RELATIONSHIP) { + return relationshipName; + } else if (kind == IStructureViewNode.Kind.LINK) { + return programElement.toLinkLabelString(); + } else { + return programElement.toLabelString(); + } + } + +} + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNodeFactory.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNodeFactory.java new file mode 100644 index 000000000..02b8ba52c --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNodeFactory.java @@ -0,0 +1,52 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.util.List; + +import org.aspectj.ajde.IconRegistry; +import org.aspectj.ajde.ui.*; +import org.aspectj.asm.*; + +/** + * @author Mik Kersten + */ +public class SwingTreeViewNodeFactory extends StructureViewNodeFactory { + + public SwingTreeViewNodeFactory(IconRegistry iconRegistry) { + super(iconRegistry); + } + + protected IStructureViewNode createDeclaration( + IProgramElement node, + AbstractIcon icon, + List children) { + return new SwingTreeViewNode(node, icon, children); + } + + protected IStructureViewNode createLink( + IProgramElement node, + AbstractIcon icon) { + return new SwingTreeViewNode(node, icon); + } + + protected IStructureViewNode createRelationship( + IRelationship relationship, + AbstractIcon icon) { + return new SwingTreeViewNode(relationship, icon); + } + +} diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNodeRenderer.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNodeRenderer.java new file mode 100644 index 000000000..80396be73 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/SwingTreeViewNodeRenderer.java @@ -0,0 +1,93 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + +package org.aspectj.ajde.ui.swing; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; + +import javax.swing.Icon; +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeCellRenderer; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.IStructureViewNode; +import org.aspectj.asm.IProgramElement; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.ISourceLocation; + +/** + * @author Mik Kersten + */ +class SwingTreeViewNodeRenderer extends DefaultTreeCellRenderer { + + private static final long serialVersionUID = -4561164526650924465L; + + public Component getTreeCellRendererComponent(JTree tree, + Object treeNode, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + if (treeNode == null) return null; + this.setFont(StructureTree.DEFAULT_FONT); + SwingTreeViewNode viewNode = (SwingTreeViewNode)treeNode; + IProgramElement node = viewNode.getStructureNode(); + + if (viewNode.getKind() == IStructureViewNode.Kind.LINK) { + ISourceLocation sourceLoc = node.getSourceLocation(); + if ((null != sourceLoc) + && (null != sourceLoc.getSourceFile().getAbsolutePath())) { + setTextNonSelectionColor(AjdeWidgetStyles.LINK_NODE_COLOR); + } else { + setTextNonSelectionColor(AjdeWidgetStyles.LINK_NODE_NO_SOURCE_COLOR); + } + + } else if (viewNode.getKind() == IStructureViewNode.Kind.RELATIONSHIP) { + this.setFont(new Font(this.getFont().getName(), Font.ITALIC, this.getFont().getSize())); + setTextNonSelectionColor(new Color(0, 0, 0)); + + } else if (viewNode.getKind() == IStructureViewNode.Kind.DECLARATION) { + setTextNonSelectionColor(new Color(0, 0, 0)); + } + + super.getTreeCellRendererComponent(tree, treeNode, sel, expanded, leaf, row, hasFocus); + if (viewNode.getIcon() != null && viewNode.getIcon().getIconResource() != null) { + setIcon((Icon)viewNode.getIcon().getIconResource()); + } else { + setIcon(null); + } + + if (node != null) { + if (node.isRunnable()) { + setIcon(Ajde.getDefault().getIconRegistry().getExecuteIcon()); + } + if (node.getMessage() != null) { + if (node.getMessage().getKind().equals(IMessage.WARNING)) { + setIcon(Ajde.getDefault().getIconRegistry().getWarningIcon()); + } else if (node.getMessage().getKind().equals(IMessage.ERROR)) { + setIcon(Ajde.getDefault().getIconRegistry().getErrorIcon()); + } else { + setIcon(Ajde.getDefault().getIconRegistry().getInfoIcon()); + } + } + + } + return this; + } +} + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/TreeViewBuildConfigEditor.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/TreeViewBuildConfigEditor.java new file mode 100644 index 000000000..3d332c865 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/TreeViewBuildConfigEditor.java @@ -0,0 +1,298 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; + +import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; + +import org.aspectj.ajde.Ajde; +import org.aspectj.ajde.ui.BuildConfigEditor; +import org.aspectj.ajde.ui.BuildConfigModel; +import org.aspectj.ajde.ui.BuildConfigNode; +import org.aspectj.ajde.ui.InvalidResourceException; +import org.aspectj.asm.IProgramElement; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; +/** + * UI for editing build configuration (".lst") files via a graphical tree-based + * representation. + * + * @author Mik Kersten + */ +public class TreeViewBuildConfigEditor extends JPanel implements BuildConfigEditor { + + private static final long serialVersionUID = 8071799814661969685L; + private ConfigTreeNode root; +// private ConfigTreeNode currNode; + private BuildConfigModel model = null; + + private static java.util.List selectedEntries = new ArrayList(); +// private String configFile = null; +// private File sourcePath = null; + //private BuildConfigModelBuilder configTreeBuilder = new BuildConfigModelBuilder(); + + BorderLayout borderLayout1 = new BorderLayout(); + JPanel jPanel1 = new JPanel(); + JLabel jLabel1 = new JLabel(); + JPanel jPanel2 = new JPanel(); + JButton cancel_button = new JButton(); + BorderLayout borderLayout2 = new BorderLayout(); + JButton save_button = new JButton(); + JScrollPane jScrollPane = new JScrollPane(); + JTree buildConfig_tree = new JTree(); + + public void openFile(String configFile) throws IOException, InvalidResourceException { + try { + if (configFile == null) { + Message msg = new Message("No structure is selected for editing.",IMessage.ERROR,null,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + return; + } + // this.configFile = configFile; + // sourcePath = new File(new File(configFile).getParent()); + jbInit(); + jLabel1.setText(" Build configuration: " + configFile); + + model = Ajde.getDefault().getBuildConfigManager().buildModel(configFile); + root = buildTree(model.getRoot()); + + buildConfig_tree.setModel(new DefaultTreeModel(root)); + buildConfig_tree.addMouseListener(new ConfigFileMouseAdapter(buildConfig_tree)); + buildConfig_tree.setCellRenderer(new ConfigTreeCellRenderer()); + + for (int j = 0; j < buildConfig_tree.getRowCount(); j++) { + buildConfig_tree.expandPath(buildConfig_tree.getPathForRow(j)); + } + } catch(Exception e) { + Message msg = new Message("Could not open file.",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + private ConfigTreeNode buildTree(BuildConfigNode node) { + ConfigTreeNode treeNode = new ConfigTreeNode(node); + for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { + BuildConfigNode childNode = (BuildConfigNode)it.next(); + treeNode.add(buildTree(childNode)); + } + return treeNode; + } + + private void saveModel() { + Ajde.getDefault().getBuildConfigManager().writeModel(model); + } + + private void jbInit() throws Exception { + this.setLayout(borderLayout1); + jLabel1.setFont(new java.awt.Font("Dialog", 0, 11)); + jLabel1.setMaximumSize(new Dimension(80, 30)); + jLabel1.setMinimumSize(new Dimension(80, 20)); + jLabel1.setPreferredSize(new Dimension(80, 20)); + jLabel1.setText("Config File Editor"); + cancel_button.setFont(new java.awt.Font("Dialog", 0, 11)); + cancel_button.setMaximumSize(new Dimension(73, 20)); + cancel_button.setMinimumSize(new Dimension(73, 20)); + cancel_button.setPreferredSize(new Dimension(73, 20)); + cancel_button.setText("Cancel"); + cancel_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + cancel_button_actionPerformed(e); + } + }); + jPanel1.setLayout(borderLayout2); + save_button.setText("Save"); + save_button.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + save_button_actionPerformed(e); + } + }); + save_button.setPreferredSize(new Dimension(73, 20)); + save_button.setMinimumSize(new Dimension(73, 20)); + save_button.setMaximumSize(new Dimension(73, 20)); + save_button.setFont(new java.awt.Font("Dialog", 0, 11)); + this.add(jPanel1, BorderLayout.NORTH); + jPanel1.add(jPanel2, BorderLayout.EAST); + jPanel2.add(save_button, null); + //jPanel2.add(cancel_button, null); + jPanel1.add(jLabel1, BorderLayout.CENTER); + this.add(jScrollPane, BorderLayout.CENTER); + jScrollPane.getViewport().add(buildConfig_tree, null); + } + + private static class ConfigTreeNode extends DefaultMutableTreeNode { + + private static final long serialVersionUID = 1L; + public JCheckBox checkBox = null; + public BuildConfigNode modelNode; + + public ConfigTreeNode(BuildConfigNode modelNode) { + super(modelNode.getName(), true); + this.modelNode = modelNode; + checkBox = new JCheckBox(); + } + public BuildConfigNode getModelNode() { + return modelNode; + } + + public void setModelNode(BuildConfigNode modelNode) { + this.modelNode = modelNode; + } + + } + + private static class ConfigFileMouseAdapter extends MouseAdapter { + private JTree tree = null; + final JCheckBox checkBoxProto = new JCheckBox(); + final int width = checkBoxProto.getPreferredSize().width; + + public ConfigFileMouseAdapter(JTree tree) { + super(); + this.tree = tree; + } + + public void mousePressed(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + TreePath path = tree.getClosestPathForLocation(x,y); + ConfigTreeNode node = (ConfigTreeNode)path.getLastPathComponent(); + + // if (isCheckBox(x, tree.getPathBounds(path).x)) { + if (node.checkBox.isSelected()) { + node.getModelNode().setActive(false); + node.checkBox.setSelected(false); + } else { + node.getModelNode().setActive(true); + node.checkBox.setSelected(true); + } + + ((DefaultTreeModel)tree.getModel()).nodeChanged(node); + if (node.getModelNode().getName() != null) { + if (node.checkBox.isSelected()) { + selectedEntries.add(node.getModelNode().getName()); + } else { + selectedEntries.remove(node.getModelNode().getName()); + } + } + super.mousePressed(e); + + } + + boolean isCheckBox(int x, int x_) { + int d = x - x_; + return (d < width) && (d > 0); + } + } + + static class ConfigTreeCellRenderer extends DefaultTreeCellRenderer { + private static final long serialVersionUID = -3120665318910899066L; + + public Component getTreeCellRendererComponent(JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + super.getTreeCellRendererComponent(tree, value, sel, expanded, + leaf, row, hasFocus); + JPanel p = new JPanel(); + p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); + p.setBackground(Color.white); + //if (leaf) { + setFont(new Font("Dialog", Font.PLAIN, 11)); + final JCheckBox cbox = ((ConfigTreeNode)value).checkBox; + cbox.setBackground(Color.white); + if (row != 0) { + p.add(cbox); + } + + ConfigTreeNode ctn = (ConfigTreeNode)value; + //if (TreeViewBuildConfigEditor.selectedEntries.contains(ctn.getSourceFile())) { + if (ctn.getModelNode().isActive()) { + cbox.setSelected(true); + } + + if (!ctn.getModelNode().isValidResource()) { + ctn.checkBox.setEnabled(false); + } + + //} + BuildConfigNode.Kind kind = ctn.getModelNode().getBuildConfigNodeKind(); + if (kind.equals(BuildConfigNode.Kind.FILE_ASPECTJ)) { + setIcon(Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.FILE_ASPECTJ)); + } else if (kind.equals(BuildConfigNode.Kind.FILE_JAVA)) { + setIcon(Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.FILE_JAVA)); + } else if (kind.equals(BuildConfigNode.Kind.FILE_LST)) { + setIcon(Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.FILE_LST)); + } else if (kind.equals(BuildConfigNode.Kind.DIRECTORY)) { + setIcon(Ajde.getDefault().getIconRegistry().getStructureSwingIcon(IProgramElement.Kind.PACKAGE)); + } else { + setIcon((Icon)Ajde.getDefault().getIconRegistry().getIcon(IProgramElement.Kind.ERROR).getIconResource()); + p.remove(cbox); + } + +// if (ctn.getModelNode().getResourcePath() != null) { +// if (ctn.getModelNode().getResourcePath().endsWith(".java")) { +// this.setIcon(AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.CLASS)); +// } else if (ctn.getModelNode().getResourcePath().endsWith(".aj")) { +// this.setIcon(AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.ASPECT)); +// } else { +// this.setIcon(AjdeUIManager.getDefault().getIconRegistry().getStructureSwingIcon(ProgramElementNode.Kind.PACKAGE)); +// } +// } + + p.add(this); + return p; + } + } + + void cancel_button_actionPerformed(ActionEvent e) { + //resetEditorFrame(); + } + + void save_button_actionPerformed(ActionEvent e) { + saveModel(); + //resetEditorFrame(); + } + +// private void resetEditorFrame() { +// BrowserManager.getDefault().resetEditorFrame(); +// } +} + diff --git a/ajde/src/main/java/org/aspectj/ajde/ui/swing/UpdateConfigurationDialog.java b/ajde/src/main/java/org/aspectj/ajde/ui/swing/UpdateConfigurationDialog.java new file mode 100644 index 000000000..2fc7bf201 --- /dev/null +++ b/ajde/src/main/java/org/aspectj/ajde/ui/swing/UpdateConfigurationDialog.java @@ -0,0 +1,237 @@ +/* ******************************************************************* + * Copyright (c) 1999-2001 Xerox Corporation, + * 2002 Palo Alto Research Center, Incorporated (PARC). + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation + * Helen Hawkins Converted to new interface (bug 148190) + * ******************************************************************/ + + + +package org.aspectj.ajde.ui.swing; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.Vector; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ListCellRenderer; +import javax.swing.border.TitledBorder; + +import org.aspectj.ajde.Ajde; +import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.Message; + +/** + * Used for automatically updating build configuration files (".lst") when a + * project configuration has changed. + * + * @author Mik Kersten + */ +public class UpdateConfigurationDialog extends JFrame { + private static final long serialVersionUID = 5885112642841314728L; +// private Vector buildConfigFiles; +// private Vector filesToUpdate; +// private boolean addToConfiguration; + + private String message1 = " Project has been updated."; + private String message2 = " File list below."; + private Box box5; + private JButton cancel_button = new JButton(); + private JButton ok_button = new JButton(); + private FlowLayout flowLayout1 = new FlowLayout(); + private JPanel globalButton_panel = new JPanel(); + private JPanel jPanel1 = new JPanel(); + private JPanel jPanel2 = new JPanel(); + private TitledBorder titledBorder1; + private TitledBorder titledBorder2; + private BorderLayout borderLayout1 = new BorderLayout(); + private BorderLayout borderLayout2 = new BorderLayout(); + private BorderLayout borderLayout3 = new BorderLayout(); + private JPanel jPanel3 = new JPanel(); + private GridLayout gridLayout1 = new GridLayout(); + private JScrollPane jScrollPane1 = new JScrollPane(); + private JList updatedFilesList = new JList(); + private JScrollPane jScrollPane2 = new JScrollPane(); + private JList buildConfigList = new JList(); + private Box box2; + private JLabel messageLabel1 = new JLabel(); + private JLabel messageLabel2 = new JLabel(); + + public UpdateConfigurationDialog(Vector filesToUpdate, Vector buildConfigFiles, boolean addToConfiguration, Component parentComponent) { + try { +// this.buildConfigFiles = buildConfigFiles; +// this.filesToUpdate = filesToUpdate; +// this.addToConfiguration = addToConfiguration; + + updatedFilesList.setListData(filesToUpdate); + String action = "removed from"; + if (addToConfiguration) action = "added to"; + message1 = " Files have been " + action + " the project, which will affect the build configurations\n"; + message2 = " listed below. These build configurations listed can be updated automatically."; + + //buildConfigList.setCellRenderer(new CheckListCellRenderer()); + //CheckListener listener = new CheckListener(buildConfigList); + buildConfigList.setListData(buildConfigFiles); + + jbInit(); + + this.doLayout(); + this.setTitle("Build Configuration Update"); + this.setSize(500, 320); + + // center it + int posX = parentComponent.getX() + 100;//(parentComponent.getWidth()/2); + int posY = parentComponent.getY() + 100;//(parentComponent.getHeight()/2); + this.setLocation(posX, posY); + } + catch(Exception e) { + Message msg = new Message("Could not open configuration dialog",IMessage.ERROR,e,null); + Ajde.getDefault().getMessageHandler().handleMessage(msg); + } + } + + void cancel_button_actionPerformed(ActionEvent e) { + this.dispose(); + } + void ok_button_actionPerformed(ActionEvent e) { +// Object[] selected = buildConfigList.getSelectedValues(); +// //LstBuildConfigFileUpdater.updateBuildConfigFiles(buildConfigFiles, filesToUpdate, addToConfiguration); + this.dispose(); + } + + private void jbInit() throws Exception { + box5 = Box.createVerticalBox(); + titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)),"Project Files Added/Removed"); + titledBorder2 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)),"Build Configurations Affected"); + box2 = Box.createVerticalBox(); + this.getContentPane().setLayout(borderLayout1); + cancel_button.setText("Cancel"); + cancel_button.addActionListener(new java.awt.event.ActionListener() { + + public void actionPerformed(ActionEvent e) { + cancel_button_actionPerformed(e); + } + }); + ok_button.setText("Update Selected Configurations"); + ok_button.addActionListener(new java.awt.event.ActionListener() { + + public void actionPerformed(ActionEvent e) { + ok_button_actionPerformed(e); + } + }); + globalButton_panel.setLayout(flowLayout1); + jPanel1.setLayout(borderLayout3); + jPanel1.setBorder(titledBorder1); + jPanel1.setMinimumSize(new Dimension(154, 20)); + jPanel1.setPreferredSize(new Dimension(154, 50)); + jPanel2.setBorder(titledBorder2); + jPanel2.setMinimumSize(new Dimension(36, 50)); + jPanel2.setPreferredSize(new Dimension(272, 50)); + jPanel2.setLayout(borderLayout2); + globalButton_panel.setMinimumSize(new Dimension(297, 37)); + globalButton_panel.setPreferredSize(new Dimension(297, 37)); + jPanel3.setLayout(gridLayout1); + jPanel3.setMinimumSize(new Dimension(154, 20)); + jPanel3.setPreferredSize(new Dimension(154, 40)); + buildConfigList.setBorder(BorderFactory.createLoweredBevelBorder()); + messageLabel1.setText(message1); + messageLabel2.setText(message2); + updatedFilesList.setFont(new java.awt.Font("Dialog", 0, 10)); + this.getContentPane().add(box5, BorderLayout.CENTER); + box5.add(jPanel3, null); + jPanel3.add(box2, null); + box2.add(messageLabel1, null); + box2.add(messageLabel2, null); + box5.add(jPanel1, null); + jPanel1.add(jScrollPane1, BorderLayout.CENTER); + jScrollPane1.getViewport().add(updatedFilesList, null); + box5.add(jPanel2, null); + jPanel2.add(jScrollPane2, BorderLayout.CENTER); + jScrollPane2.getViewport().add(buildConfigList, null); + box5.add(globalButton_panel, null); + globalButton_panel.add(ok_button, null); + globalButton_panel.add(cancel_button, null); + } +} + +class CheckListCellRenderer extends JCheckBox implements ListCellRenderer { + private static final long serialVersionUID = -9183012434083509581L; + + public CheckListCellRenderer() { + super(); + setOpaque(true); + } + + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + setText(value.toString()); + setFont(new java.awt.Font("Dialog", 0, 10)); + setBackground(new Color(255, 255, 255)); + + setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); + setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); + setSelected(isSelected); + + return this; + } +} + +class CheckListener implements MouseListener, KeyListener { + + protected JList list; + + public CheckListener(JList list) { + this.list = list; + } + + public void mouseClicked(MouseEvent e) { + doCheck(); + } + + public void keyPressed(KeyEvent e) { + if (e.getKeyChar() == ' ') doCheck(); + } + + protected void doCheck() { + int index = list.getSelectedIndex(); + if (index < 0) { + return; + } + list.getModel().getElementAt(index); + list.repaint(); + } + + public void mousePressed(MouseEvent e) {} + public void mouseReleased(MouseEvent e) {} + public void mouseEntered(MouseEvent e) {} + public void mouseExited(MouseEvent e) {} + public void keyTyped(KeyEvent e) {} + public void keyReleased(KeyEvent e) { } +} |