Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Harley2005-09-23 22:13:49 +0000
committerWalter Harley2005-09-23 22:13:49 +0000
commit30a0d8b166ac2fa2854a231544dfecb8e382982a (patch)
tree71438682ec21d3447488172d8f8e9f1cee4d7b47 /org.eclipse.jdt.apt.ui/src/org
parent6a39aeee024a65d73e9084e99bead655e3ded072 (diff)
downloadeclipse.jdt.core-30a0d8b166ac2fa2854a231544dfecb8e382982a.tar.gz
eclipse.jdt.core-30a0d8b166ac2fa2854a231544dfecb8e382982a.tar.xz
eclipse.jdt.core-30a0d8b166ac2fa2854a231544dfecb8e382982a.zip
wharley - Implement "run in batch mode" flag for annotation processors, including API and GUI support. External clients that used the FactoryPath or FactoryContainer APIs will be broken, and should switch to using IFactoryPath.
Diffstat (limited to 'org.eclipse.jdt.apt.ui/src/org')
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AdvancedFactoryPathOptionsDialog.java92
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathConfigurationBlock.java388
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathPreferencePage.java4
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java6
-rw-r--r--org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties3
5 files changed, 384 insertions, 109 deletions
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AdvancedFactoryPathOptionsDialog.java b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AdvancedFactoryPathOptionsDialog.java
new file mode 100644
index 0000000000..352904dbba
--- /dev/null
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/AdvancedFactoryPathOptionsDialog.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2005 BEA Systems, Inc.
+ * 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:
+ * wharley@bea.com - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.apt.ui.internal.preferences;
+
+import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
+import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
+import org.eclipse.jface.dialogs.StatusDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog to display "advanced options" on a FactoryPathEntry,
+ * typically in the context of the factory path config UI.
+ * Advanced options are those which do not normally need to
+ * be configured, and which may require deeper-than-usual
+ * understanding of the annotation processing architecture.
+ */
+public class AdvancedFactoryPathOptionsDialog extends StatusDialog {
+
+ private class FieldAdapter implements IDialogFieldListener {
+ public void dialogFieldChanged(DialogField field) {
+ }
+ }
+
+ // shallow copies, because they are not changed by this code
+ private final FactoryContainer _fc;
+ private final FactoryPath.Attributes _attr;
+
+ private SelectionButtonDialogField _batchModeField;
+
+ public AdvancedFactoryPathOptionsDialog(
+ Shell parent, FactoryContainer fc, FactoryPath.Attributes attr) {
+ super(parent);
+ _fc= fc;
+ _attr= attr;
+
+ setTitle(Messages.AdvancedFactoryPathOptionsDialog_advancedOptions);
+
+ FieldAdapter adapter = new FieldAdapter();
+
+ _batchModeField = new SelectionButtonDialogField(SWT.CHECK);
+ _batchModeField.setSelection(_attr.runInBatchMode());
+ _batchModeField.setLabelText(Messages.AdvancedFactoryPathOptionsDialog_batchMode);
+ _batchModeField.setDialogFieldListener(adapter);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite composite= (Composite) super.createDialogArea(parent);
+
+ Composite inner= new Composite(composite, SWT.NONE);
+ GridLayout layout= new GridLayout();
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ layout.numColumns= 2;
+ inner.setLayout(layout);
+
+ _batchModeField.doFillIntoGrid(inner, 2);
+
+ // Plugins can't run in APT compatibility mode.
+ boolean isPlugin = _fc.getType() == FactoryContainer.FactoryType.PLUGIN;
+ _batchModeField.setEnabled(!isPlugin);
+
+ applyDialogFont(composite);
+ return composite;
+ }
+
+ /**
+ * Return a new Attributes representing the original value updated
+ * with any changes made by the user. Changes will be included even
+ * if the dialog was cancelled, so this should only be called if the
+ * dialog returned OK.
+ */
+ public FactoryPath.Attributes getResult() {
+ boolean batchMode = _batchModeField.isSelected();
+ return new FactoryPath.Attributes(_attr.isEnabled(), batchMode);
+ }
+}
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathConfigurationBlock.java b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathConfigurationBlock.java
index 97eb990dcd..ce66eeae5f 100644
--- a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathConfigurationBlock.java
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathConfigurationBlock.java
@@ -11,7 +11,10 @@
package org.eclipse.jdt.apt.ui.internal.preferences;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
@@ -20,21 +23,36 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.apt.core.FactoryContainer;
-import org.eclipse.jdt.apt.core.util.FactoryPath;
+import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
+import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
+import org.eclipse.jdt.apt.core.internal.util.FactoryPathUtil;
+import org.eclipse.jdt.apt.core.internal.util.FactoryPath.Attributes;
+import org.eclipse.jdt.apt.core.util.AptConfig;
+import org.eclipse.jdt.apt.core.util.IFactoryPath;
import org.eclipse.jdt.apt.ui.internal.util.ExceptionHandler;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.ui.util.CoreUtility;
import org.eclipse.jdt.internal.ui.util.PixelConverter;
import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
-import org.eclipse.jdt.internal.ui.wizards.dialogfields.*;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.CheckedListDialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
+import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField;
import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
@@ -52,10 +70,11 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
private static final int IDX_ADDVAR= 5;
// 6
private static final int IDX_EDIT= 7;
- private static final int IDX_REMOVE= 8;
- // 9
- private static final int IDX_ENABLEALL= 10;
- private static final int IDX_DISABLEALL= 11;
+ private static final int IDX_ADVANCED= 8;
+ private static final int IDX_REMOVE= 9;
+ // 10
+ private static final int IDX_ENABLEALL= 11;
+ private static final int IDX_DISABLEALL= 12;
private final static String[] buttonLabels = {
Messages.FactoryPathConfigurationBlock_up,
@@ -66,27 +85,13 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
Messages.FactoryPathConfigurationBlock_addVariable,
null, // 6
Messages.FactoryPathConfigurationBlock_edit,
+ Messages.FactoryPathConfigurationBlock_advanced,
Messages.FactoryPathConfigurationBlock_remove,
- null, // 9
+ null, // 10
Messages.FactoryPathConfigurationBlock_enableAll,
Messages.FactoryPathConfigurationBlock_disableAll
};
- private PixelConverter fPixelConverter;
- private Composite fBlockControl; // the control representing the entire configuration block
-
- private class ListEntry {
- public final String fS;
- public boolean fB;
- ListEntry(String s) {
- fS = s;
- fB = false;
- }
- public String toString() {
- return fS;
- }
- }
-
/**
* Event handler for factory path list control
*/
@@ -102,6 +107,13 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
field.enableButton(IDX_EDIT, enableEdit);
}
+ /**
+ * This method gets called when, among other things, a checkbox is
+ * clicked. However, it doesn't get any information about which
+ * item it was whose checkbox was clicked, so it's pretty useless.
+ * Instead of maintaining the FactoryPathEntry states here, we
+ * hook into the list control's CheckboxTableViewer event listener.
+ */
public void dialogFieldChanged(DialogField field) {
}
@@ -112,11 +124,80 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
}
}
+ private class FactoryPathLabelProvider extends LabelProvider implements ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (!(element instanceof FactoryPathEntry)) {
+ return ""; //$NON-NLS-1$
+ }
+ FactoryPathEntry fpe = (FactoryPathEntry)element;
+ if (columnIndex == 0) {
+ return fpe._fc.toString();
+ }
+ else {
+ return ""; //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * The factory path is a list of containers, plus some information about
+ * each container. That makes it a list of FactoryPathEntry.
+ */
+ private static class FactoryPathEntry {
+ /* shallow copies - beware! */
+ public final FactoryContainer _fc;
+ public FactoryPath.Attributes _attr;
+
+ // CONSTRUCTORS
+ public FactoryPathEntry(FactoryContainer fc, FactoryPath.Attributes attr) {
+ _fc = fc;
+ _attr = attr;
+ }
+
+ // CONVERSION TO/FROM INDIVIDUAL ELEMENTS
+ public static Map<FactoryContainer, Attributes> pathMapFromList(List<FactoryPathEntry> list) {
+ Map<FactoryContainer, FactoryPath.Attributes> map =
+ new LinkedHashMap<FactoryContainer, FactoryPath.Attributes>(list.size());
+ for (FactoryPathEntry fpe : list) {
+ map.put(fpe._fc, fpe._attr);
+ }
+ return map;
+ }
+ public static List<FactoryPathEntry> pathListFromMap(Map<FactoryContainer, Attributes> map) {
+ List<FactoryPathEntry> list = new ArrayList<FactoryPathEntry>(map.size());
+ for (Map.Entry<FactoryContainer, Attributes> entry : map.entrySet()) {
+ FactoryPathEntry fpe = new FactoryPathEntry(entry.getKey(), entry.getValue());
+ list.add(fpe);
+ }
+ return list;
+ }
+
+ // SUPPORT FOR COMPARISON
+ public boolean equals(Object obj) {
+ if (!(obj instanceof FactoryPathEntry))
+ return false;
+ FactoryPathEntry fpe = (FactoryPathEntry)obj;
+ return _fc.equals(fpe._fc) && _attr.equals(fpe._attr);
+ }
+ public int hashCode() {
+ return _fc.hashCode() ^ _attr.hashCode();
+ }
+
+ }
+
+ private PixelConverter fPixelConverter;
+ private Composite fBlockControl; // the control representing the entire configuration block
+
/**
* The factory path at the time this pref pane was launched.
* Use this to see if anything changed at save time.
*/
- private Map<FactoryContainer, Boolean> fOriginalPath;
+ private List<FactoryPathEntry> fOriginalPath;
/**
* True if the pref pane is for a project and project-specific
@@ -127,6 +208,10 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
private final IJavaProject fJProj;
+ /**
+ * The GUI control representing the factory path. Its data items
+ * are of type FactoryPathEntry.
+ */
private CheckedListDialogField fFactoryPathList;
/**
@@ -142,8 +227,9 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
fJProj = JavaCore.create(project);
FactoryPathAdapter adapter= new FactoryPathAdapter();
+ FactoryPathLabelProvider labelProvider = new FactoryPathLabelProvider();
- fFactoryPathList= new CheckedListDialogField(adapter, buttonLabels, new LabelProvider());
+ fFactoryPathList= new CheckedListDialogField(adapter, buttonLabels, labelProvider);
fFactoryPathList.setDialogFieldListener(adapter);
fFactoryPathList.setLabelText(Messages.FactoryPathConfigurationBlock_pluginsAndJars);
fFactoryPathList.setUpButtonIndex(IDX_UP);
@@ -154,13 +240,28 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
}
/**
+ * Respond to the user checking the "enabled" checkbox of an entry
+ * in the factory path control, by replacing the FactoryPathEntry
+ * with a new one with the correct "enabled" value.
+ */
+ protected void doCheckStateChanged(CheckStateChangedEvent e) {
+ Object o = e.getElement();
+ if (o == null || !(o instanceof FactoryPathEntry)) {
+ return; // shouldn't ever happen
+ }
+ FactoryPathEntry fpe = (FactoryPathEntry)o;
+ boolean isChecked = e.getChecked();
+ fpe._attr.setEnabled(isChecked);
+ }
+
+ /**
* Respond to a button in the button bar.
* Most buttons are handled by code in CheckedListDialogField;
* this method is for the rest, e.g., Add External Jar.
* @param index
*/
public void customButtonPressed(int index) {
- FactoryContainer[] newEntries = null;
+ FactoryPathEntry[] newEntries = null;
switch (index) {
case IDX_ADDJAR: // add jars in project
newEntries= openJarFileDialog(null);
@@ -182,6 +283,10 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
editSelectedItem();
}
break;
+
+ case IDX_ADVANCED: // advanced options
+ advancedOptionsDialog();
+ break;
}
}
@@ -190,10 +295,10 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
* Can't remove a selection that contains a plugin.
*/
private boolean canRemove() {
- List selected= fFactoryPathList.getSelectedElements();
+ List<FactoryPathEntry> selected= getSelectedListContents();
boolean containsPlugin= false;
- for (Object o : selected) {
- if (((FactoryContainer)o).getType() == FactoryContainer.FactoryType.PLUGIN) {
+ for (FactoryPathEntry fpe : selected) {
+ if (fpe._fc.getType() == FactoryContainer.FactoryType.PLUGIN) {
containsPlugin = true;
break;
}
@@ -205,20 +310,20 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
* Can only edit a single item at a time. Can't edit plugins.
*/
private boolean canEdit() {
- List selected= fFactoryPathList.getSelectedElements();
+ List<FactoryPathEntry> selected= getSelectedListContents();
if (selected.size() != 1) {
return false;
}
- FactoryContainer fc = (FactoryContainer)selected.get(0);
+ FactoryContainer fc = selected.get(0)._fc;
return (fc.getType() != FactoryContainer.FactoryType.PLUGIN);
}
- private void addEntries(FactoryContainer[] entries) {
+ private void addEntries(FactoryPathEntry[] entries) {
if (null == entries) {
return;
}
int insertAt;
- List selectedElements= fFactoryPathList.getSelectedElements();
+ List<FactoryPathEntry> selectedElements= getSelectedListContents();
if (selectedElements.size() == 1) {
insertAt= fFactoryPathList.getIndexOfElement(selectedElements.get(0)) + 1;
} else {
@@ -226,7 +331,7 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
}
for (int i = 0; i < entries.length; ++i) {
fFactoryPathList.addElement(entries[i], insertAt + i);
- fFactoryPathList.setChecked(entries[i], true);
+ fFactoryPathList.setChecked(entries[i], entries[i]._attr.isEnabled());
}
}
@@ -237,13 +342,13 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
* @param field a listbox of FactoryContainers.
*/
private void editSelectedItem() {
- List selected= fFactoryPathList.getSelectedElements();
+ List<FactoryPathEntry> selected= getSelectedListContents();
if (selected.size() != 1) {
return;
}
- FactoryContainer original = (FactoryContainer)selected.get(0);
- FactoryContainer[] edited = null;
- switch (original.getType()) {
+ FactoryPathEntry original = selected.get(0);
+ FactoryPathEntry[] edited = null;
+ switch (original._fc.getType()) {
case PLUGIN:
return;
case EXTJAR:
@@ -284,6 +389,14 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
cacheOriginalValues();
initListContents();
+ // Register a change listener on the checkboxes
+ CheckboxTableViewer tableViewer = (CheckboxTableViewer)fFactoryPathList.getTableViewer();
+ tableViewer.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent e) {
+ doCheckStateChanged(e);
+ }
+ });
+
//TODO: enable help
//PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.BUILD_PATH_BLOCK);
return fBlockControl;
@@ -295,10 +408,11 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
*/
private void initListContents() {
fFactoryPathList.removeAllElements();
- for (Map.Entry<FactoryContainer, Boolean> e : fOriginalPath.entrySet()) {
- FactoryContainer fc = e.getKey();
- fFactoryPathList.addElement(fc);
- fFactoryPathList.setChecked(fc, e.getValue());
+ for (FactoryPathEntry originalFpe : fOriginalPath) {
+ // clone, because we may later modify it and we want to compare with the original.
+ FactoryPathEntry fpe = new FactoryPathEntry(originalFpe._fc, originalFpe._attr);
+ fFactoryPathList.addElement(fpe);
+ fFactoryPathList.setChecked(fpe, fpe._attr.isEnabled());
}
}
@@ -308,16 +422,29 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
* to work; so be sure to call this any time you save (eg in performApply()).
*/
private void cacheOriginalValues() {
- fOriginalPath = FactoryPath.getAllContainers(fJProj);
- fOriginallyProjectSpecific = FactoryPath.hasProjectSpecificFactoryPath(fJProj);
+ IFactoryPath ifp = AptConfig.getFactoryPath(fJProj);
+ // we'll risk this downcast because we're such good buddies with apt.core.
+ FactoryPath fp = (FactoryPath)ifp;
+ Map<FactoryContainer, FactoryPath.Attributes> path = fp.getAllContainers();
+ fOriginalPath = FactoryPathEntry.pathListFromMap(path);
+ fOriginallyProjectSpecific = AptConfig.hasProjectSpecificFactoryPath(fJProj);
+ }
+
+ /*
+ * Helper method to get rid of unchecked conversion warning
+ */
+ @SuppressWarnings("unchecked") //$NON-NLS-1$
+ private List<FactoryPathEntry> getListContents() {
+ List<FactoryPathEntry> contents= fFactoryPathList.getElements();
+ return contents;
}
/*
* Helper method to get rid of unchecked conversion warning
*/
@SuppressWarnings("unchecked") //$NON-NLS-1$
- private List<FactoryContainer> getListContents() {
- List<FactoryContainer> contents= fFactoryPathList.getElements();
+ private List<FactoryPathEntry> getSelectedListContents() {
+ List<FactoryPathEntry> contents= fFactoryPathList.getSelectedElements();
return contents;
}
@@ -336,10 +463,11 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
if (type == FactoryContainer.FactoryType.PLUGIN) {
throw new IllegalArgumentException();
}
- List<FactoryContainer> all = getListContents();
+ List<FactoryPathEntry> all = getListContents();
// find out how many entries there are of this type
int countType = 0;
- for (FactoryContainer fc : all) {
+ for (FactoryPathEntry fpe : all) {
+ FactoryContainer fc = fpe._fc;
if (fc.getType() == type && fc != ignore) {
++countType;
}
@@ -347,50 +475,82 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
// create an array of paths, one per entry of this type
IPath[] some = new IPath[countType];
int i = 0;
- for (FactoryContainer fc : all) {
+ for (FactoryPathEntry fpe : all) {
+ FactoryContainer fc = fpe._fc;
if (fc.getType() == type && fc != ignore) {
some[i++] = new Path(fc.getId());
}
}
return some;
}
+
+ /**
+ * Launch the "advanced options" dialog, which displays the factory classes
+ * contained by the selected container and allows the user to specify
+ * options that are needed only in certain special cases.
+ *
+ * We treat advanced options as an attribute of the factory path, not of the
+ * container; the same container may have different advanced options in different
+ * projects. We treat advanced options the same way as the "enabled" flag.
+ */
+ private void advancedOptionsDialog() {
+ List<FactoryPathEntry> selected= getSelectedListContents();
+ if (selected.size() != 1) {
+ return;
+ }
+ FactoryPathEntry original= selected.get(0);
+ AdvancedFactoryPathOptionsDialog dialog=
+ new AdvancedFactoryPathOptionsDialog(getShell(), original._fc, original._attr);
+ if (dialog.open() == Window.OK) {
+ original._attr = dialog.getResult();
+ // If the dialog could change the enabled attribute, we would also
+ // need to update the checkbox in the GUI here. But it doesn't.
+ }
+ }
/**
* Add or edit a project-relative jar file. Only possible when editing
* project properties; this method is disabled in workspace prefs.
* @param original null, or an existing list entry to be edited
- * @return a list of additional factory containers to be added
+ * @return a list of additional factory path entries to be added
*/
- private FactoryContainer[] openJarFileDialog(FactoryContainer original) {
+ private FactoryPathEntry[] openJarFileDialog(FactoryPathEntry original) {
if (fJProj == null) {
return null;
}
IWorkspaceRoot root= fJProj.getProject().getWorkspace().getRoot();
- IPath[] existingPaths = getExistingPaths(FactoryContainer.FactoryType.WKSPJAR, original);
+ IPath[] existingPaths = getExistingPaths(FactoryContainer.FactoryType.WKSPJAR, original._fc);
if (original == null) {
IPath[] results= BuildPathDialogAccess.chooseJAREntries(getShell(), fJProj.getPath(), existingPaths);
if (results == null) {
return null;
}
- ArrayList<FactoryContainer> res= new ArrayList<FactoryContainer>();
+ ArrayList<FactoryPathEntry> res= new ArrayList<FactoryPathEntry>();
for (int i= 0; i < results.length; i++) {
IResource resource= root.findMember(results[i]);
if (resource instanceof IFile) {
- res.add(FactoryPath.newWkspJarFactoryContainer(results[i]));
+ FactoryContainer fc = FactoryPathUtil.newWkspJarFactoryContainer(results[i]);
+ // assume defaults of enabled=true, runInAptMode=false
+ FactoryPath.Attributes attr = new FactoryPath.Attributes(true, false);
+ FactoryPathEntry fpe = new FactoryPathEntry(fc, attr);
+ res.add(fpe);
}
//TODO: handle missing jars
}
- return res.toArray(new FactoryContainer[res.size()]);
+ return res.toArray(new FactoryPathEntry[res.size()]);
}
else {
- IPath result= BuildPathDialogAccess.configureJAREntry(getShell(), new Path(original.getId()), existingPaths);
+ IPath result= BuildPathDialogAccess.configureJAREntry(getShell(), new Path(original._fc.getId()), existingPaths);
if (result == null) {
return null;
}
IResource resource= root.findMember(result);
if (resource instanceof IFile) {
- FactoryContainer[] edited = new FactoryContainer[1];
- edited[0]= FactoryPath.newWkspJarFactoryContainer(result);
+ FactoryPathEntry[] edited = new FactoryPathEntry[1];
+ FactoryContainer fc= FactoryPathUtil.newWkspJarFactoryContainer(result);
+ // Use prior value for isEnabled. Assume default of runInAptMode=false
+ FactoryPath.Attributes attr = new FactoryPath.Attributes(original._attr.isEnabled(), false);
+ edited[0]= new FactoryPathEntry(fc, attr);
return edited;
}
//TODO: handle missing jars
@@ -398,49 +558,74 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
}
}
- private FactoryContainer[] openExtJarFileDialog(FactoryContainer existing) {
- if (existing == null) {
+ /**
+ * Add or edit an external (not project-relative) jar file.
+ * @param original null, or an existing list entry to be edited
+ * @return a list of additional factory path entries to be added
+ */
+ private FactoryPathEntry[] openExtJarFileDialog(FactoryPathEntry original) {
+ if (original == null) {
IPath[] selected= BuildPathDialogAccess.chooseExternalJAREntries(getShell());
if (selected == null) {
return null;
}
- ArrayList<FactoryContainer> res= new ArrayList<FactoryContainer>();
+ ArrayList<FactoryPathEntry> res= new ArrayList<FactoryPathEntry>();
for (int i= 0; i < selected.length; i++) {
- res.add(FactoryPath.newExtJarFactoryContainer(selected[i].toFile()));
+ FactoryContainer fc = FactoryPathUtil.newExtJarFactoryContainer(selected[i].toFile());
+ // assume defaults of enabled=true, runInAptMode=false
+ FactoryPath.Attributes attr = new FactoryPath.Attributes(true, false);
+ FactoryPathEntry fpe = new FactoryPathEntry(fc, attr);
+ res.add(fpe);
}
- return res.toArray(new FactoryContainer[res.size()]);
+ return res.toArray(new FactoryPathEntry[res.size()]);
}
else {
- IPath result= BuildPathDialogAccess.configureExternalJAREntry(getShell(), new Path(existing.getId()));
+ IPath result= BuildPathDialogAccess.configureExternalJAREntry(getShell(), new Path(original._fc.getId()));
if (result == null) {
return null;
}
- FactoryContainer[] edited= new FactoryContainer[1];
- edited[0]= FactoryPath.newExtJarFactoryContainer(result.toFile());
+ FactoryPathEntry[] edited= new FactoryPathEntry[1];
+ FactoryContainer fc= FactoryPathUtil.newExtJarFactoryContainer(result.toFile());
+ // Use prior value for isEnabled. Assume default of runInAptMode=false
+ FactoryPath.Attributes attr = new FactoryPath.Attributes(original._attr.isEnabled(), false);
+ edited[0]= new FactoryPathEntry(fc, attr);
return edited;
}
}
- private FactoryContainer[] openVariableSelectionDialog(FactoryContainer original) {
- IPath[] existingPaths = getExistingPaths(FactoryContainer.FactoryType.VARJAR, original);
+ /**
+ * Add or edit an external (not project-relative) jar file whose
+ * location includes a classpath variable name.
+ * @param original null, or an existing list entry to be edited
+ * @return a list of additional factory path entries to be added
+ */
+ private FactoryPathEntry[] openVariableSelectionDialog(FactoryPathEntry original) {
+ IPath[] existingPaths = getExistingPaths(FactoryContainer.FactoryType.VARJAR, original._fc);
if (original == null) {
IPath[] selected= BuildPathDialogAccess.chooseVariableEntries(getShell(), existingPaths);
if (selected == null) {
return null;
}
- ArrayList<FactoryContainer> res= new ArrayList<FactoryContainer>();
+ ArrayList<FactoryPathEntry> res= new ArrayList<FactoryPathEntry>();
for (int i= 0; i < selected.length; i++) {
- res.add(FactoryPath.newVarJarFactoryContainer(selected[i]));
+ FactoryContainer fc= FactoryPathUtil.newVarJarFactoryContainer(selected[i]);
+ // assume defaults of enabled=true, runInAptMode=false
+ FactoryPath.Attributes attr = new FactoryPath.Attributes(true, false);
+ FactoryPathEntry fpe = new FactoryPathEntry(fc, attr);
+ res.add(fpe);
}
- return res.toArray(new FactoryContainer[res.size()]);
+ return res.toArray(new FactoryPathEntry[res.size()]);
}
else {
- IPath result= BuildPathDialogAccess.configureVariableEntry(getShell(), new Path(original.getId()), existingPaths);
+ IPath result= BuildPathDialogAccess.configureVariableEntry(getShell(), new Path(original._fc.getId()), existingPaths);
if (result == null) {
return null;
}
- FactoryContainer[] edited= new FactoryContainer[1];
- edited[0]= FactoryPath.newVarJarFactoryContainer(result);
+ FactoryPathEntry[] edited= new FactoryPathEntry[1];
+ FactoryContainer fc= FactoryPathUtil.newVarJarFactoryContainer(result);
+ // Use prior value for isEnabled. Assume default of runInAptMode=false
+ FactoryPath.Attributes attr = new FactoryPath.Attributes(original._attr.isEnabled(), false);
+ edited[0]= new FactoryPathEntry(fc, attr);
return edited;
}
}
@@ -460,7 +645,7 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
}
private void saveSettings() {
- Map<FactoryContainer, Boolean> containers;
+ List<FactoryPathEntry> containers;
if ((fJProj != null) && !fBlockControl.isEnabled()) {
// We're in a project properties pane but the entire configuration
// block control is disabled. That means the per-project settings checkbox
@@ -468,17 +653,15 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
containers = null;
}
else {
- containers = new LinkedHashMap<FactoryContainer, Boolean>();
- int count = fFactoryPathList.getSize();
- for (int i = 0; i < count; ++i) {
- FactoryContainer fc = (FactoryContainer)fFactoryPathList.getElement(i);
- Boolean enabled = fFactoryPathList.isChecked(fc);
- containers.put(fc, new Boolean(enabled));
- }
+ containers = getListContents();
}
+ Map<FactoryContainer, FactoryPath.Attributes> map = FactoryPathEntry.pathMapFromList(containers);
+
try {
- FactoryPath.setContainers(fJProj, containers);
+ FactoryPath fp = new FactoryPath();
+ fp.setContainers(map);
+ AptConfig.setFactoryPath(fJProj, fp);
}
catch (CoreException e) {
final String title = Messages.FactoryPathConfigurationBlock_unableToSaveFactorypath_title;
@@ -493,12 +676,15 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
* If workspace, restore list contents to factory-default settings.
*/
public void performDefaults() {
- Map<FactoryContainer, Boolean> defaults = FactoryPath.getDefaultFactoryPath(fJProj);
+ IFactoryPath ifp = AptConfig.getDefaultFactoryPath(fJProj);
+ // we'll risk this downcast because we're such good buddies with apt.core.
+ FactoryPath fp = (FactoryPath)ifp;
+ Map<FactoryContainer, FactoryPath.Attributes> map = fp.getAllContainers();
+ List<FactoryPathEntry> defaults = FactoryPathEntry.pathListFromMap(map);
fFactoryPathList.removeAllElements();
- for (Map.Entry<FactoryContainer, Boolean> e : defaults.entrySet()) {
- FactoryContainer fc = e.getKey();
- fFactoryPathList.addElement(fc);
- fFactoryPathList.setChecked(fc, e.getValue());
+ for (FactoryPathEntry fpe : defaults) {
+ fFactoryPathList.addElement(fpe);
+ fFactoryPathList.setChecked(fpe, fpe._attr.isEnabled());
}
super.performDefaults();
}
@@ -564,26 +750,14 @@ public class FactoryPathConfigurationBlock extends BaseConfigurationBlock {
// no project specific data, and there never was, so nothing could have changed.
return false;
}
- int count = fFactoryPathList.getSize();
- if (fOriginalPath.size() != count) {
- // something was added or removed
+ if (fOriginalPath == null) {
+ // shouldn't happen, but just in case it does, consider it a change.
return true;
}
- // now we know both lists are the same size
- Iterator<Map.Entry<FactoryContainer, Boolean>> iOriginal = fOriginalPath.entrySet().iterator();
- for (int i = 0; i < count; ++i) {
- Map.Entry<FactoryContainer, Boolean> entry = iOriginal.next();
- Boolean wasEnabled = entry.getValue();
- FactoryContainer fc = (FactoryContainer)fFactoryPathList.getElement(i);
- if (!fc.equals(entry.getKey())) {
- return true;
- }
- Boolean isEnabled = fFactoryPathList.isChecked(fc);
- if (isEnabled ^ wasEnabled) {
- return true;
- }
- }
- return false;
+ // Is the new path the same size, containing the same items
+ // in the same order? We rely on FactoryPathEntry.equals() here.
+ List<FactoryPathEntry> newPath = getListContents();
+ return !fOriginalPath.equals(newPath);
}
}
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathPreferencePage.java b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathPreferencePage.java
index 5b4ef16bc8..696294a033 100644
--- a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathPreferencePage.java
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/FactoryPathPreferencePage.java
@@ -12,7 +12,7 @@
package org.eclipse.jdt.apt.ui.internal.preferences;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.apt.core.util.FactoryPath;
+import org.eclipse.jdt.apt.core.util.AptConfig;
import org.eclipse.jdt.apt.ui.AptUIPlugin;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.swt.widgets.Composite;
@@ -52,7 +52,7 @@ public class FactoryPathPreferencePage extends BasePreferencePage {
protected boolean hasProjectSpecificOptions(IProject project) {
useProjectSettings();
- return (project == null) ? false : FactoryPath.hasProjectSpecificFactoryPath(JavaCore.create(project));
+ return (project == null) ? false : AptConfig.hasProjectSpecificFactoryPath(JavaCore.create(project));
}
/* (non-Javadoc)
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java
index 5ec65aae45..8f17c7f545 100644
--- a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/Messages.java
@@ -97,4 +97,10 @@ public class Messages extends NLS {
public static String ProcessorOptionInputDialog_equalsSignNotValid;
public static String AptConfigurationBlock_genSrcDirMustBeValidRelativePath;
+
+ public static String FactoryPathConfigurationBlock_advanced;
+
+ public static String AdvancedFactoryPathOptionsDialog_advancedOptions;
+
+ public static String AdvancedFactoryPathOptionsDialog_batchMode;
}
diff --git a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties
index 9ddfb780cf..09a3f3b8e8 100644
--- a/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties
+++ b/org.eclipse.jdt.apt.ui/src/org/eclipse/jdt/apt/ui/internal/preferences/messages.properties
@@ -14,6 +14,7 @@ FactoryPathConfigurationBlock_up=Up
FactoryPathConfigurationBlock_down=Down
FactoryPathConfigurationBlock_edit=Edit...
FactoryPathConfigurationBlock_addJars=Add Jars...
+FactoryPathConfigurationBlock_advanced=Advanced...
FactoryPathPreferencePage_factoryPath=Java annotation processor factory path:
FactoryPathPreferencePage_preferences=Factory Path Preferences
FactoryPathConfigurationBlock_addExternalJars=Add External Jars...
@@ -35,3 +36,5 @@ ProcessorOptionInputDialog_equalsSignNotValid=The equals sign is not a valid cha
ProcessorOptionInputDialog_key=Key:
ProcessorOptionInputDialog_value=Value:
ProcessorOptionInputDialog_emptyKey=Please enter a key
+AdvancedFactoryPathOptionsDialog_advancedOptions=Advanced Options
+AdvancedFactoryPathOptionsDialog_batchMode=Run in batch mode

Back to the top