KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > ui > internal > preferences > AdvancedFactoryPathOptionsDialog


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * wharley@bea.com - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.apt.ui.internal.preferences;
13
14 import java.io.IOException JavaDoc;
15 import java.util.Map.Entry;
16
17 import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
18 import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
19 import org.eclipse.jdt.apt.ui.internal.util.ExceptionHandler;
20 import org.eclipse.jdt.apt.ui.internal.util.IAptHelpContextIds;
21 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
22 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
23 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
24 import org.eclipse.jface.dialogs.Dialog;
25 import org.eclipse.jface.viewers.ListViewer;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.ui.PlatformUI;
33
34 /**
35  * Dialog to display "advanced options" on a FactoryPathEntry,
36  * typically in the context of the factory path config UI.
37  * Advanced options are those which do not normally need to
38  * be configured, and which may require deeper-than-usual
39  * understanding of the annotation processing architecture.
40  */

41 public class AdvancedFactoryPathOptionsDialog extends Dialog {
42     
43     private final static int LIST_WIDTH= 70; // width (in chars) of factory list
44
private final static int LIST_HEIGHT= 10; // number of lines in factory list
45

46     private class FieldAdapter implements IDialogFieldListener {
47         public void dialogFieldChanged(DialogField field) {
48         }
49     }
50     
51     // shallow copies, because they are not changed by this code
52
private final FactoryContainer _fc;
53     private final FactoryPath.Attributes _attr;
54     
55     // Dialog controls
56
private SelectionButtonDialogField _batchModeField;
57     private ListViewer _contentsField;
58     
59     public AdvancedFactoryPathOptionsDialog(
60             Shell parent, FactoryContainer fc, FactoryPath.Attributes attr) {
61         super(parent);
62         setShellStyle(getShellStyle() | SWT.RESIZE);
63         _fc= fc;
64         _attr= attr;
65     }
66     
67     protected void configureShell(Shell shell) {
68         super.configureShell(shell);
69         shell.setText(Messages.AdvancedFactoryPathOptionsDialog_advancedOptions);
70         PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IAptHelpContextIds.ADVANCED_FACTORYPATH_OPTIONS_DIALOG);
71     }
72     
73     protected Control createDialogArea(Composite parent) {
74         Composite dlgArea= (Composite) super.createDialogArea(parent);
75         
76         // Set up "batch mode" checkbox.
77
FieldAdapter adapter = new FieldAdapter();
78         _batchModeField = new SelectionButtonDialogField(SWT.CHECK);
79         _batchModeField.setSelection(_attr.runInBatchMode());
80         _batchModeField.setLabelText(Messages.AdvancedFactoryPathOptionsDialog_batchMode);
81         _batchModeField.setDialogFieldListener(adapter);
82         _batchModeField.doFillIntoGrid(dlgArea, 2);
83             // Plugins can't run in APT compatibility mode.
84
boolean isPlugin = _fc.getType() == FactoryContainer.FactoryType.PLUGIN;
85         _batchModeField.setEnabled(!isPlugin);
86         
87         DialogField.createEmptySpace(dlgArea, 1);
88
89         // Set up label for processor contents list
90
Label description= new Label(dlgArea, SWT.WRAP);
91         description.setText(Messages.AdvancedFactoryPathOptionsDialog_label_processorsInThisContainer);
92         GridData gdLabel= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
93         gdLabel.horizontalSpan= 2;
94         description.setLayoutData(gdLabel);
95
96         // Set up processor contents list
97
_contentsField= new ListViewer(dlgArea, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
98         GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
99         data.heightHint = convertHeightInCharsToPixels(LIST_HEIGHT);
100         data.widthHint = convertWidthInCharsToPixels(LIST_WIDTH);
101         _contentsField.getList().setLayoutData(data);
102         _contentsField.getList().setFont(parent.getFont());
103         try {
104             for (Entry<String JavaDoc, String JavaDoc> entry : _fc.getFactoryNames().entrySet()) {
105                 String JavaDoc name = entry.getKey();
106                 _contentsField.add(name);
107                 //TODO: display the processor type (i.e., entry.getValue())
108
}
109         }
110         catch (IOException JavaDoc e) {
111             final String JavaDoc message = "Unable to load factory names from container [" + _fc.getId() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
112
ExceptionHandler.log(e, message);
113         }
114         _contentsField.setSelection(null, false);
115         
116         applyDialogFont(dlgArea);
117         return dlgArea;
118     }
119         
120     /**
121      * Return a new Attributes representing the original value updated
122      * with any changes made by the user. Changes will be included even
123      * if the dialog was cancelled, so this should only be called if the
124      * dialog returned OK.
125      */

126     public FactoryPath.Attributes getResult() {
127         boolean batchMode = _batchModeField.isSelected();
128         return new FactoryPath.Attributes(_attr.isEnabled(), batchMode);
129     }
130 }
131
Popular Tags