001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 BEA Systems, Inc.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * wharley@bea.com - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.apt.ui.internal.preferences;
011:
012: import java.io.IOException;
013: import java.util.Map.Entry;
014:
015: import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
016: import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
017: import org.eclipse.jdt.apt.ui.internal.util.ExceptionHandler;
018: import org.eclipse.jdt.apt.ui.internal.util.IAptHelpContextIds;
019: import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
020: import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
021: import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
022: import org.eclipse.jface.dialogs.Dialog;
023: import org.eclipse.jface.viewers.ListViewer;
024: import org.eclipse.swt.SWT;
025: import org.eclipse.swt.layout.GridData;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.swt.widgets.Label;
029: import org.eclipse.swt.widgets.Shell;
030: import org.eclipse.ui.PlatformUI;
031:
032: /**
033: * Dialog to display "advanced options" on a FactoryPathEntry,
034: * typically in the context of the factory path config UI.
035: * Advanced options are those which do not normally need to
036: * be configured, and which may require deeper-than-usual
037: * understanding of the annotation processing architecture.
038: */
039: public class AdvancedFactoryPathOptionsDialog extends Dialog {
040:
041: private final static int LIST_WIDTH = 70; // width (in chars) of factory list
042: private final static int LIST_HEIGHT = 10; // number of lines in factory list
043:
044: private class FieldAdapter implements IDialogFieldListener {
045: public void dialogFieldChanged(DialogField field) {
046: }
047: }
048:
049: // shallow copies, because they are not changed by this code
050: private final FactoryContainer _fc;
051: private final FactoryPath.Attributes _attr;
052:
053: // Dialog controls
054: private SelectionButtonDialogField _batchModeField;
055: private ListViewer _contentsField;
056:
057: public AdvancedFactoryPathOptionsDialog(Shell parent,
058: FactoryContainer fc, FactoryPath.Attributes attr) {
059: super (parent);
060: setShellStyle(getShellStyle() | SWT.RESIZE);
061: _fc = fc;
062: _attr = attr;
063: }
064:
065: protected void configureShell(Shell shell) {
066: super .configureShell(shell);
067: shell
068: .setText(Messages.AdvancedFactoryPathOptionsDialog_advancedOptions);
069: PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
070: IAptHelpContextIds.ADVANCED_FACTORYPATH_OPTIONS_DIALOG);
071: }
072:
073: protected Control createDialogArea(Composite parent) {
074: Composite dlgArea = (Composite) super .createDialogArea(parent);
075:
076: // Set up "batch mode" checkbox.
077: FieldAdapter adapter = new FieldAdapter();
078: _batchModeField = new SelectionButtonDialogField(SWT.CHECK);
079: _batchModeField.setSelection(_attr.runInBatchMode());
080: _batchModeField
081: .setLabelText(Messages.AdvancedFactoryPathOptionsDialog_batchMode);
082: _batchModeField.setDialogFieldListener(adapter);
083: _batchModeField.doFillIntoGrid(dlgArea, 2);
084: // Plugins can't run in APT compatibility mode.
085: boolean isPlugin = _fc.getType() == FactoryContainer.FactoryType.PLUGIN;
086: _batchModeField.setEnabled(!isPlugin);
087:
088: DialogField.createEmptySpace(dlgArea, 1);
089:
090: // Set up label for processor contents list
091: Label description = new Label(dlgArea, SWT.WRAP);
092: description
093: .setText(Messages.AdvancedFactoryPathOptionsDialog_label_processorsInThisContainer);
094: GridData gdLabel = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
095: gdLabel.horizontalSpan = 2;
096: description.setLayoutData(gdLabel);
097:
098: // Set up processor contents list
099: _contentsField = new ListViewer(dlgArea, SWT.SINGLE
100: | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
101: GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
102: data.heightHint = convertHeightInCharsToPixels(LIST_HEIGHT);
103: data.widthHint = convertWidthInCharsToPixels(LIST_WIDTH);
104: _contentsField.getList().setLayoutData(data);
105: _contentsField.getList().setFont(parent.getFont());
106: try {
107: for (Entry<String, String> entry : _fc.getFactoryNames()
108: .entrySet()) {
109: String name = entry.getKey();
110: _contentsField.add(name);
111: //TODO: display the processor type (i.e., entry.getValue())
112: }
113: } catch (IOException e) {
114: final String message = "Unable to load factory names from container [" + _fc.getId() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
115: ExceptionHandler.log(e, message);
116: }
117: _contentsField.setSelection(null, false);
118:
119: applyDialogFont(dlgArea);
120: return dlgArea;
121: }
122:
123: /**
124: * Return a new Attributes representing the original value updated
125: * with any changes made by the user. Changes will be included even
126: * if the dialog was cancelled, so this should only be called if the
127: * dialog returned OK.
128: */
129: public FactoryPath.Attributes getResult() {
130: boolean batchMode = _batchModeField.isSelected();
131: return new FactoryPath.Attributes(_attr.isEnabled(), batchMode);
132: }
133: }
|