001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
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: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.tools;
011:
012: import org.eclipse.jface.dialogs.Dialog;
013: import org.eclipse.jface.dialogs.IDialogSettings;
014: import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
015: import org.eclipse.pde.internal.ui.IHelpContextIds;
016: import org.eclipse.pde.internal.ui.IPreferenceConstants;
017: import org.eclipse.pde.internal.ui.PDEUIMessages;
018: import org.eclipse.pde.internal.ui.refactoring.PDERefactor;
019: import org.eclipse.swt.SWT;
020: import org.eclipse.swt.events.SelectionAdapter;
021: import org.eclipse.swt.events.SelectionEvent;
022: import org.eclipse.swt.layout.GridData;
023: import org.eclipse.swt.layout.GridLayout;
024: import org.eclipse.swt.widgets.Button;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Group;
027: import org.eclipse.swt.widgets.Label;
028: import org.eclipse.swt.widgets.Text;
029: import org.eclipse.ui.PlatformUI;
030:
031: public class OrganizeManifestsWizardPage extends UserInputWizardPage
032: implements IPreferenceConstants, IOrganizeManifestsSettings {
033:
034: private Button fRemoveUnresolved;
035: private Button fCalculateUses;
036: private Button fAddMissing;
037: private Button fMarkInternal;
038: private Text fPackageFilter;
039: private Label fPackageFilterLabel;
040: private Button fRemoveImport;
041: private Button fOptionalImport;
042: private Button fModifyDependencies;
043: private Button fUnusedDependencies;
044: private Button fAdditonalDependencies;
045: private Button fFixIconNLSPaths;
046: private Button fRemovedUnusedKeys;
047: private Button fRemoveLazy;
048:
049: private Button[] fTopLevelButtons; // used for setting page complete state
050:
051: private OrganizeManifestsProcessor fProcessor;
052:
053: private static String title = PDEUIMessages.OrganizeManifestsWizardPage_title;
054:
055: protected OrganizeManifestsWizardPage() {
056: super (title);
057: setTitle(title);
058: setDescription(PDEUIMessages.OrganizeManifestsWizardPage_description);
059: }
060:
061: public void createControl(Composite parent) {
062: Composite container = new Composite(parent, SWT.NONE);
063: container.setLayout(new GridLayout());
064: container.setLayoutData(new GridData(GridData.FILL_BOTH));
065:
066: fProcessor = (OrganizeManifestsProcessor) ((PDERefactor) getRefactoring())
067: .getProcessor();
068:
069: createExportedPackagesGroup(container);
070: createRequireImportGroup(container);
071: createGeneralGroup(container);
072: createNLSGroup(container);
073:
074: // init
075: setButtonArrays();
076: presetOptions();
077: hookListeners();
078:
079: setControl(container);
080: PlatformUI.getWorkbench().getHelpSystem().setHelp(container,
081: IHelpContextIds.ORGANIZE_MANIFESTS);
082: Dialog.applyDialogFont(container);
083: }
084:
085: private void createExportedPackagesGroup(Composite container) {
086: Group group = createGroup(
087: container,
088: PDEUIMessages.OrganizeManifestsWizardPage_exportedGroup,
089: 1, true);
090:
091: fAddMissing = new Button(group, SWT.CHECK);
092: fAddMissing
093: .setText(PDEUIMessages.OrganizeManifestsWizardPage_addMissing);
094:
095: fMarkInternal = new Button(group, SWT.CHECK);
096: fMarkInternal
097: .setText(PDEUIMessages.OrganizeManifestsWizardPage_markInternal);
098:
099: Composite comp = new Composite(group, SWT.NONE);
100: GridLayout layout = new GridLayout(2, false);
101: layout.marginHeight = layout.marginWidth = 0;
102: comp.setLayout(layout);
103: comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
104: fPackageFilterLabel = new Label(comp, SWT.NONE);
105: fPackageFilterLabel
106: .setText(PDEUIMessages.OrganizeManifestsWizardPage_packageFilter);
107: GridData gd = new GridData();
108: gd.horizontalIndent = 20;
109: fPackageFilterLabel.setLayoutData(gd);
110: fPackageFilter = new Text(comp, SWT.BORDER);
111: fPackageFilter.setLayoutData(new GridData(
112: GridData.FILL_HORIZONTAL));
113:
114: fRemoveUnresolved = new Button(group, SWT.CHECK);
115: fRemoveUnresolved
116: .setText(PDEUIMessages.OrganizeManifestsWizardPage_removeUnresolved);
117: gd = new GridData();
118: gd.verticalIndent = 5;
119: fRemoveUnresolved.setLayoutData(gd);
120:
121: fCalculateUses = new Button(group, SWT.CHECK);
122: fCalculateUses
123: .setText(PDEUIMessages.OrganizeManifestsWizardPage_calculateUses);
124: gd = new GridData();
125: gd.verticalIndent = 5;
126: fCalculateUses.setLayoutData(gd);
127: }
128:
129: private void createRequireImportGroup(Composite container) {
130: Group group = createGroup(
131: container,
132: PDEUIMessages.OrganizeManifestsWizardPage_dependenciesGroup,
133: 1, true);
134:
135: Composite comp = new Composite(group, SWT.NONE);
136: GridLayout layout = new GridLayout(3, false);
137: layout.marginHeight = layout.marginWidth = 0;
138: comp.setLayout(layout);
139: comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
140:
141: fModifyDependencies = new Button(comp, SWT.CHECK);
142: fModifyDependencies
143: .setText(PDEUIMessages.OrganizeManifestsWizardPage_unresolvedDependencies);
144:
145: fRemoveImport = new Button(comp, SWT.RADIO);
146: fRemoveImport
147: .setText(PDEUIMessages.OrganizeManifestsWizardPage_remove);
148:
149: fOptionalImport = new Button(comp, SWT.RADIO);
150: fOptionalImport
151: .setText(PDEUIMessages.OrganizeManifestsWizardPage_markOptional);
152:
153: fUnusedDependencies = new Button(group, SWT.CHECK);
154: fUnusedDependencies
155: .setText(PDEUIMessages.OrganizeManifestsWizardPage_removeUnused);
156:
157: fAdditonalDependencies = new Button(group, SWT.CHECK);
158: fAdditonalDependencies
159: .setText(PDEUIMessages.OrganizeManifestsWizardPage_addDependencies);
160: }
161:
162: private void createGeneralGroup(Composite container) {
163: Group group = createGroup(container,
164: PDEUIMessages.OrganizeManifestsWizardPage_generalGroup,
165: 1, true);
166:
167: fRemoveLazy = new Button(group, SWT.CHECK);
168: fRemoveLazy
169: .setText(PDEUIMessages.OrganizeManifestsWizardPage_lazyStart);
170: }
171:
172: private void createNLSGroup(Composite container) {
173: Group group = createGroup(
174: container,
175: PDEUIMessages.OrganizeManifestsWizardPage_internationalizationGroup,
176: 1, true);
177:
178: fFixIconNLSPaths = new Button(group, SWT.CHECK);
179: fFixIconNLSPaths
180: .setText(PDEUIMessages.OrganizeManifestsWizardPage_prefixNL);
181:
182: fRemovedUnusedKeys = new Button(group, SWT.CHECK);
183: fRemovedUnusedKeys
184: .setText(PDEUIMessages.OrganizeManifestsWizardPage_removeUnusedKeys);
185: }
186:
187: private Group createGroup(Composite parent, String text, int span,
188: boolean colsEqual) {
189: Group group = new Group(parent, SWT.NONE);
190: group.setText(text);
191: GridLayout layout = new GridLayout(span, colsEqual);
192: layout.marginHeight = layout.marginWidth = 10;
193: group.setLayout(layout);
194: GridData gd = new GridData(GridData.FILL_BOTH);
195: group.setLayoutData(gd);
196: return group;
197: }
198:
199: private void presetOptions() {
200: IDialogSettings settings = getDialogSettings();
201:
202: boolean selection = !settings.getBoolean(PROP_ADD_MISSING);
203: fAddMissing.setSelection(selection);
204: fProcessor.setAddMissing(selection);
205:
206: selection = !settings.getBoolean(PROP_MARK_INTERNAL);
207: fMarkInternal.setSelection(selection);
208: fProcessor.setMarkInternal(selection);
209:
210: String filter = settings.get(PROP_INTERAL_PACKAGE_FILTER);
211: if (filter == null)
212: filter = VALUE_DEFAULT_FILTER;
213: fPackageFilter.setText(filter);
214: fProcessor.setPackageFilter(filter);
215:
216: selection = !settings.getBoolean(PROP_REMOVE_UNRESOLVED_EX);
217: fRemoveUnresolved.setSelection(selection);
218: fProcessor.setRemoveUnresolved(selection);
219:
220: selection = settings.getBoolean(PROP_CALCULATE_USES);
221: fCalculateUses.setSelection(selection);
222: fProcessor.setCalculateUses(selection);
223:
224: selection = !settings.getBoolean(PROP_MODIFY_DEP);
225: fModifyDependencies.setSelection(selection);
226: fProcessor.setModifyDep(selection);
227:
228: selection = settings.getBoolean(PROP_RESOLVE_IMP_MARK_OPT);
229: fRemoveImport.setSelection(!selection);
230: fOptionalImport.setSelection(selection);
231: fProcessor.setRemoveDependencies(!selection);
232:
233: selection = settings.getBoolean(PROP_UNUSED_DEPENDENCIES);
234: fUnusedDependencies.setSelection(selection);
235: fProcessor.setUnusedDependencies(selection);
236:
237: selection = settings.getBoolean(PROP_ADD_DEPENDENCIES);
238: fAdditonalDependencies.setSelection(selection);
239: fProcessor.setAddDependencies(selection);
240:
241: selection = !settings.getBoolean(PROP_REMOVE_LAZY);
242: fRemoveLazy.setSelection(selection);
243: fProcessor.setRemoveLazy(selection);
244:
245: selection = settings.getBoolean(PROP_NLS_PATH);
246: fFixIconNLSPaths.setSelection(selection);
247: fProcessor.setPrefixIconNL(selection);
248:
249: selection = settings.getBoolean(PROP_UNUSED_KEYS);
250: fRemovedUnusedKeys.setSelection(selection);
251: fProcessor.setUnusedKeys(selection);
252:
253: setEnabledStates();
254: setPageComplete();
255: }
256:
257: protected void preformOk() {
258: IDialogSettings settings = getDialogSettings();
259:
260: settings.put(PROP_ADD_MISSING, !fAddMissing.getSelection());
261: settings.put(PROP_MARK_INTERNAL, !fMarkInternal.getSelection());
262: settings.put(PROP_INTERAL_PACKAGE_FILTER, fPackageFilter
263: .getText());
264: settings.put(PROP_REMOVE_UNRESOLVED_EX, !fRemoveUnresolved
265: .getSelection());
266: settings
267: .put(PROP_CALCULATE_USES, fCalculateUses.getSelection());
268:
269: settings.put(PROP_MODIFY_DEP, !fModifyDependencies
270: .getSelection());
271: settings.put(PROP_RESOLVE_IMP_MARK_OPT, fOptionalImport
272: .getSelection());
273: settings.put(PROP_UNUSED_DEPENDENCIES, fUnusedDependencies
274: .getSelection());
275: settings.put(PROP_ADD_DEPENDENCIES, fAdditonalDependencies
276: .getSelection());
277:
278: settings.put(PROP_REMOVE_LAZY, !fRemoveLazy.getSelection());
279:
280: settings.put(PROP_NLS_PATH, fFixIconNLSPaths.getSelection());
281: settings.put(PROP_UNUSED_KEYS, fRemovedUnusedKeys
282: .getSelection());
283: }
284:
285: private void setEnabledStates() {
286: boolean markInternal = fMarkInternal.getSelection();
287: fPackageFilter.setEnabled(markInternal);
288: fPackageFilter.setEditable(markInternal);
289: fPackageFilterLabel.setEnabled(markInternal);
290:
291: boolean modifyDependencies = fModifyDependencies.getSelection();
292: fRemoveImport.setEnabled(modifyDependencies);
293: fOptionalImport.setEnabled(modifyDependencies);
294: }
295:
296: private void setButtonArrays() {
297: fTopLevelButtons = new Button[] { fRemoveUnresolved,
298: fAddMissing, fModifyDependencies, fMarkInternal,
299: fUnusedDependencies, fAdditonalDependencies,
300: fFixIconNLSPaths, fRemovedUnusedKeys, fRemoveLazy,
301: fCalculateUses };
302: }
303:
304: private void setPageComplete() {
305: boolean pageComplete = false;
306: for (int i = 0; i < fTopLevelButtons.length; i++) {
307: if (fTopLevelButtons[i].getSelection()) {
308: pageComplete = true;
309: break;
310: }
311: }
312: setPageComplete(pageComplete);
313: }
314:
315: private void hookListeners() {
316: hookListener(
317: new Button[] { fMarkInternal, fModifyDependencies },
318: new SelectionAdapter() {
319: public void widgetSelected(SelectionEvent e) {
320: setEnabledStates();
321: doProcessorSetting(e.getSource());
322: }
323: });
324: hookListener(fTopLevelButtons, new SelectionAdapter() {
325: public void widgetSelected(SelectionEvent e) {
326: setPageComplete();
327: doProcessorSetting(e.getSource());
328: }
329: });
330: hookListener(new Button[] { fRemoveImport, fOptionalImport },
331: new SelectionAdapter() {
332: public void widgetSelected(SelectionEvent e) {
333: doProcessorSetting(e.getSource());
334: }
335: });
336: }
337:
338: private void doProcessorSetting(Object source) {
339: if (fProcessor == null)
340: return;
341: if (fAddMissing.equals(source))
342: fProcessor.setAddMissing(fAddMissing.getSelection());
343: else if (fMarkInternal.equals(source))
344: fProcessor.setMarkInternal(fMarkInternal.getSelection());
345: else if (fPackageFilter.equals(source))
346: fProcessor.setPackageFilter(fPackageFilter.getText());
347: else if (fRemoveUnresolved.equals(source))
348: fProcessor.setRemoveUnresolved(fRemoveUnresolved
349: .getSelection());
350: else if (fCalculateUses.equals(source))
351: fProcessor.setCalculateUses(fCalculateUses.getSelection());
352: else if (fModifyDependencies.equals(source))
353: fProcessor.setModifyDep(fModifyDependencies.getSelection());
354: else if (fOptionalImport.equals(source))
355: fProcessor.setRemoveDependencies(!fOptionalImport
356: .getSelection());
357: else if (fRemoveImport.equals(source))
358: fProcessor.setRemoveDependencies(fRemoveImport
359: .getSelection());
360: else if (fUnusedDependencies.equals(source))
361: fProcessor.setUnusedDependencies(fUnusedDependencies
362: .getSelection());
363: else if (fAdditonalDependencies.equals(source))
364: fProcessor.setAddDependencies(fAdditonalDependencies
365: .getSelection());
366: else if (fRemoveLazy.equals(source))
367: fProcessor.setRemoveLazy(fRemoveLazy.getSelection());
368: else if (fFixIconNLSPaths.equals(source))
369: fProcessor.setPrefixIconNL(fFixIconNLSPaths.getSelection());
370: else if (fRemovedUnusedKeys.equals(source))
371: fProcessor.setUnusedKeys(fRemovedUnusedKeys.getSelection());
372: }
373:
374: private void hookListener(Button[] buttons, SelectionAdapter adapter) {
375: for (int i = 0; i < buttons.length; i++) {
376: buttons[i].addSelectionListener(adapter);
377: }
378: }
379: }
|