001: /*******************************************************************************
002: * Copyright (c) 2000, 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.preferences;
011:
012: import java.io.BufferedInputStream;
013: import java.io.IOException;
014: import java.io.InputStream;
015: import java.net.URL;
016: import java.util.ArrayList;
017: import java.util.StringTokenizer;
018:
019: import org.eclipse.core.resources.IFile;
020: import org.eclipse.core.runtime.CoreException;
021: import org.eclipse.core.runtime.IConfigurationElement;
022: import org.eclipse.core.runtime.IPath;
023: import org.eclipse.core.runtime.Path;
024: import org.eclipse.core.runtime.Preferences;
025: import org.eclipse.core.variables.IStringVariableManager;
026: import org.eclipse.core.variables.VariablesPlugin;
027: import org.eclipse.jface.dialogs.Dialog;
028: import org.eclipse.jface.dialogs.IDialogConstants;
029: import org.eclipse.jface.dialogs.MessageDialog;
030: import org.eclipse.jface.preference.PreferencePage;
031: import org.eclipse.jface.window.Window;
032: import org.eclipse.jface.wizard.WizardDialog;
033: import org.eclipse.pde.core.plugin.IPluginModelBase;
034: import org.eclipse.pde.core.plugin.TargetPlatform;
035: import org.eclipse.pde.internal.core.ICoreConstants;
036: import org.eclipse.pde.internal.core.PDECore;
037: import org.eclipse.pde.internal.core.PDEExtensionRegistry;
038: import org.eclipse.pde.internal.core.PDEState;
039: import org.eclipse.pde.internal.core.TargetDefinitionManager;
040: import org.eclipse.pde.internal.core.itarget.IAdditionalLocation;
041: import org.eclipse.pde.internal.core.itarget.ILocationInfo;
042: import org.eclipse.pde.internal.core.itarget.ITarget;
043: import org.eclipse.pde.internal.core.itarget.ITargetModel;
044: import org.eclipse.pde.internal.core.target.TargetModel;
045: import org.eclipse.pde.internal.ui.IHelpContextIds;
046: import org.eclipse.pde.internal.ui.PDEPlugin;
047: import org.eclipse.pde.internal.ui.PDEUIMessages;
048: import org.eclipse.pde.internal.ui.editor.target.OpenTargetProfileAction;
049: import org.eclipse.pde.internal.ui.util.FileExtensionFilter;
050: import org.eclipse.pde.internal.ui.util.FileValidator;
051: import org.eclipse.pde.internal.ui.util.SWTUtil;
052: import org.eclipse.pde.internal.ui.wizards.target.NewTargetDefinitionWizard;
053: import org.eclipse.swt.SWT;
054: import org.eclipse.swt.custom.BusyIndicator;
055: import org.eclipse.swt.events.ModifyEvent;
056: import org.eclipse.swt.events.ModifyListener;
057: import org.eclipse.swt.events.SelectionAdapter;
058: import org.eclipse.swt.events.SelectionEvent;
059: import org.eclipse.swt.layout.GridData;
060: import org.eclipse.swt.layout.GridLayout;
061: import org.eclipse.swt.widgets.Button;
062: import org.eclipse.swt.widgets.Combo;
063: import org.eclipse.swt.widgets.Composite;
064: import org.eclipse.swt.widgets.Control;
065: import org.eclipse.swt.widgets.DirectoryDialog;
066: import org.eclipse.swt.widgets.Group;
067: import org.eclipse.swt.widgets.Label;
068: import org.eclipse.swt.widgets.Link;
069: import org.eclipse.swt.widgets.TabFolder;
070: import org.eclipse.swt.widgets.TabItem;
071: import org.eclipse.ui.IWorkbench;
072: import org.eclipse.ui.IWorkbenchPreferencePage;
073: import org.eclipse.ui.PlatformUI;
074: import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
075: import org.eclipse.ui.model.WorkbenchContentProvider;
076: import org.eclipse.ui.model.WorkbenchLabelProvider;
077:
078: public class TargetPlatformPreferencePage extends PreferencePage
079: implements IWorkbenchPreferencePage {
080:
081: public static final int PLUGINS_INDEX = 0;
082: public static final int ENVIRONMENT_INDEX = 1;
083: public static final int SOURCE_INDEX = 4;
084:
085: private Label fHomeLabel;
086: private Combo fHomeText;
087: private Combo fProfileCombo;
088: private Button fBrowseButton;
089: private Button fLoadProfileButton;
090:
091: private TargetPluginsTab fPluginsTab;
092: private TargetEnvironmentTab fEnvironmentTab;
093: private JavaArgumentsTab fArgumentsTab;
094: private TargetImplicitPluginsTab fImplicitDependenciesTab;
095: private TargetSourceTab fSourceTab;
096: private IConfigurationElement[] fElements;
097:
098: private Preferences fPreferences = null;
099: protected boolean fNeedsReload = false;
100: private String fOriginalText;
101: private int fIndex;
102: private TabFolder fTabFolder;
103: private boolean fContainsWorkspaceProfile = false;
104: private Button fResetButton;
105:
106: /**
107: * MainPreferencePage constructor comment.
108: */
109: public TargetPlatformPreferencePage() {
110: this (PLUGINS_INDEX);
111: }
112:
113: public TargetPlatformPreferencePage(int index) {
114: setDescription(PDEUIMessages.Preferences_TargetPlatformPage_Description);
115: fPreferences = PDECore.getDefault().getPluginPreferences();
116: fPluginsTab = new TargetPluginsTab(this );
117: fIndex = index;
118: }
119:
120: public void dispose() {
121: // null pointer check - bug 168337
122: if (fPluginsTab != null)
123: fPluginsTab.dispose();
124: if (fSourceTab != null)
125: fSourceTab.dispose();
126: super .dispose();
127: }
128:
129: public Control createContents(Composite parent) {
130: Composite container = new Composite(parent, SWT.NONE);
131: GridLayout layout = new GridLayout();
132: layout.marginHeight = layout.marginWidth = 0;
133: container.setLayout(layout);
134:
135: createCurrentTargetPlatformGroup(container);
136: createTargetProfilesGroup(container);
137:
138: Dialog.applyDialogFont(container);
139: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
140: IHelpContextIds.TARGET_PLATFORM_PREFERENCE_PAGE);
141: return container;
142: }
143:
144: private void createTargetProfilesGroup(Composite container) {
145: Group profiles = new Group(container, SWT.NONE);
146: profiles
147: .setText(PDEUIMessages.TargetPlatformPreferencePage_TargetGroupTitle);
148: profiles.setLayout(new GridLayout(4, false));
149: profiles.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
150:
151: Link profile = new Link(profiles, SWT.NONE);
152: profile
153: .setText(PDEUIMessages.TargetPlatformPreferencePage_CurrentProfileLabel);
154: profile.addSelectionListener(new SelectionAdapter() {
155: public void widgetSelected(SelectionEvent e) {
156: if (!fProfileCombo.getText().equals("")) //$NON-NLS-1$
157: new OpenTargetProfileAction(getShell(),
158: getTargetModel(), fProfileCombo.getText())
159: .run();
160: else
161: openTargetWizard();
162: }
163: });
164:
165: fProfileCombo = new Combo(profiles, SWT.BORDER | SWT.READ_ONLY);
166: loadTargetCombo();
167: fProfileCombo.setLayoutData(new GridData(
168: GridData.FILL_HORIZONTAL));
169:
170: Button browse = new Button(profiles, SWT.PUSH);
171: browse
172: .setText(PDEUIMessages.TargetPlatformPreferencePage_BrowseButton);
173: GridData gd = new GridData();
174: browse.setLayoutData(gd);
175: browse.addSelectionListener(new SelectionAdapter() {
176: public void widgetSelected(SelectionEvent e) {
177: handleTargetBrowse();
178: }
179: });
180: SWTUtil.setButtonDimensionHint(browse);
181:
182: fLoadProfileButton = new Button(profiles, SWT.PUSH);
183: fLoadProfileButton
184: .setText(PDEUIMessages.TargetPlatformPreferencePage_ApplyButton);
185: fLoadProfileButton.setLayoutData(new GridData());
186: fLoadProfileButton.addSelectionListener(new SelectionAdapter() {
187: public void widgetSelected(SelectionEvent e) {
188: handleLoadTargetProfile();
189: }
190: });
191: fLoadProfileButton.setEnabled(!fProfileCombo.getText().equals(
192: "")); //$NON-NLS-1$
193:
194: fProfileCombo.addSelectionListener(new SelectionAdapter() {
195: public void widgetSelected(SelectionEvent e) {
196: fLoadProfileButton.setEnabled(!fProfileCombo.getText()
197: .equals("")); //$NON-NLS-1$
198: }
199: });
200:
201: SWTUtil.setButtonDimensionHint(fLoadProfileButton);
202: }
203:
204: private void createCurrentTargetPlatformGroup(Composite container) {
205: Composite target = new Composite(container, SWT.NONE);
206: GridLayout layout = new GridLayout(4, false);
207: layout.marginHeight = layout.marginWidth = 0;
208: target.setLayout(layout);
209: target.setLayoutData(new GridData(GridData.FILL_BOTH));
210:
211: fHomeLabel = new Label(target, SWT.NULL);
212: fHomeLabel
213: .setText(PDEUIMessages.Preferences_TargetPlatformPage_PlatformHome);
214:
215: fHomeText = new Combo(target, SWT.NONE);
216: fHomeText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
217: ArrayList locations = new ArrayList();
218: for (int i = 0; i < 5; i++) {
219: String value = fPreferences
220: .getString(ICoreConstants.SAVED_PLATFORM + i);
221: if (value.equals("")) //$NON-NLS-1$
222: break;
223: locations.add(value);
224: }
225: String homeLocation = fPreferences
226: .getString(ICoreConstants.PLATFORM_PATH);
227: if (!locations.contains(homeLocation))
228: locations.add(0, homeLocation);
229: fHomeText.setItems((String[]) locations
230: .toArray(new String[locations.size()]));
231: fHomeText.setText(homeLocation);
232: fOriginalText = fHomeText.getText();
233: fHomeText.addModifyListener(new ModifyListener() {
234: public void modifyText(ModifyEvent e) {
235: fNeedsReload = true;
236: }
237: });
238:
239: fBrowseButton = new Button(target, SWT.PUSH);
240: fBrowseButton
241: .setText(PDEUIMessages.Preferences_TargetPlatformPage_PlatformHome_Button);
242: fBrowseButton.setLayoutData(new GridData(
243: GridData.HORIZONTAL_ALIGN_END));
244: SWTUtil.setButtonDimensionHint(fBrowseButton);
245: fBrowseButton.addSelectionListener(new SelectionAdapter() {
246: public void widgetSelected(SelectionEvent e) {
247: handleBrowse();
248: }
249: });
250:
251: fResetButton = new Button(target, SWT.PUSH);
252: fResetButton
253: .setText(PDEUIMessages.TargetPlatformPreferencePage_reset);
254: fResetButton.setLayoutData(new GridData(
255: GridData.HORIZONTAL_ALIGN_END));
256: SWTUtil.setButtonDimensionHint(fResetButton);
257: fResetButton.addSelectionListener(new SelectionAdapter() {
258: public void widgetSelected(SelectionEvent e) {
259: fHomeText.setText(TargetPlatform.getDefaultLocation());
260: fPluginsTab.handleReload(new ArrayList());
261: resetTargetProfile();
262: }
263: });
264:
265: fTabFolder = new TabFolder(target, SWT.NONE);
266: GridData gd = new GridData(GridData.FILL_BOTH);
267: gd.horizontalSpan = 4;
268: fTabFolder.setLayoutData(gd);
269:
270: BusyIndicator.showWhile(getShell().getDisplay(),
271: new Runnable() {
272: public void run() {
273: createPluginsTab(fTabFolder);
274: createEnvironmentTab(fTabFolder);
275: createArgumentsTab(fTabFolder);
276: createExplicitTab(fTabFolder);
277: createSourceTab(fTabFolder);
278: fTabFolder.setSelection(fIndex);
279: }
280: });
281:
282: fTabFolder.addSelectionListener(new SelectionAdapter() {
283: public void widgetSelected(SelectionEvent e) {
284: if (fTabFolder.getSelectionIndex() == ENVIRONMENT_INDEX) {
285: fEnvironmentTab.updateChoices();
286: }
287: }
288: });
289: }
290:
291: private void createPluginsTab(TabFolder folder) {
292: Control block = fPluginsTab.createContents(folder);
293: block.setLayoutData(new GridData(GridData.FILL_BOTH));
294: fPluginsTab.initialize();
295:
296: TabItem tab = new TabItem(folder, SWT.NONE);
297: tab
298: .setText(PDEUIMessages.TargetPlatformPreferencePage_pluginsTab);
299: tab.setControl(block);
300: }
301:
302: private void createEnvironmentTab(TabFolder folder) {
303: fEnvironmentTab = new TargetEnvironmentTab(this );
304: Control block = fEnvironmentTab.createContents(folder);
305:
306: TabItem tab = new TabItem(folder, SWT.NONE);
307: tab
308: .setText(PDEUIMessages.TargetPlatformPreferencePage_environmentTab);
309: tab.setControl(block);
310: }
311:
312: private void createSourceTab(TabFolder folder) {
313: fSourceTab = new TargetSourceTab(this );
314: Control block = fSourceTab.createContents(folder);
315:
316: TabItem tab = new TabItem(folder, SWT.NONE);
317: tab
318: .setText(PDEUIMessages.TargetPlatformPreferencePage_sourceCode);
319: tab.setControl(block);
320: }
321:
322: private void createExplicitTab(TabFolder folder) {
323: fImplicitDependenciesTab = new TargetImplicitPluginsTab(this );
324: Control block = fImplicitDependenciesTab.createContents(folder);
325:
326: TabItem tab = new TabItem(folder, SWT.NONE);
327: tab
328: .setText(PDEUIMessages.TargetPlatformPreferencePage_implicitTab);
329: tab.setControl(block);
330: }
331:
332: private void createArgumentsTab(TabFolder folder) {
333: fArgumentsTab = new JavaArgumentsTab(this );
334: Control block = fArgumentsTab.createControl(folder);
335:
336: TabItem tab = new TabItem(folder, SWT.NONE);
337: tab
338: .setText(PDEUIMessages.TargetPlatformPreferencePage_agrumentsTab);
339: tab.setControl(block);
340: }
341:
342: String getPlatformPath() {
343: return fHomeText.getText();
344: }
345:
346: private void handleBrowse() {
347: DirectoryDialog dialog = new DirectoryDialog(getShell());
348: dialog
349: .setMessage(PDEUIMessages.TargetPlatformPreferencePage_chooseInstall);
350: if (fHomeText.getText().length() > 0)
351: dialog.setFilterPath(fHomeText.getText());
352: String newPath = dialog.open();
353: if (newPath != null
354: && !new Path(fHomeText.getText()).equals(new Path(
355: newPath))) {
356: if (fHomeText.indexOf(newPath) == -1)
357: fHomeText.add(newPath, 0);
358: fHomeText.setText(newPath);
359: fPluginsTab.handleReload(new ArrayList());
360: fNeedsReload = false;
361: resetTargetProfile();
362: }
363: }
364:
365: private void loadTargetCombo() {
366: String prefId = null;
367: String pref = fPreferences
368: .getString(ICoreConstants.TARGET_PROFILE);
369: fProfileCombo.add(""); //$NON-NLS-1$
370:
371: if (pref.startsWith("${workspace_loc:")) { //$NON-NLS-1$
372: try {
373: pref = pref.substring(16, pref.length() - 1);
374: IFile file = PDEPlugin.getWorkspace().getRoot()
375: .getFile(new Path(pref));
376: addWorkspaceTarget(file);
377: } catch (CoreException e) {
378: }
379: } else if (pref.length() > 3) { //$NON-NLS-1$
380: prefId = pref.substring(3);
381: }
382:
383: //load all pre-canned (ie. registered via extension) targets
384: fElements = PDECore.getDefault().getTargetProfileManager()
385: .getSortedTargets();
386: for (int i = 0; i < fElements.length; i++) {
387: String name = fElements[i].getAttribute("name"); //$NON-NLS-1$
388: String id = fElements[i].getAttribute("id"); //$NON-NLS-1$
389: if (fProfileCombo.indexOf(name) == -1)
390: fProfileCombo.add(name);
391: if (id.equals(prefId))
392: fProfileCombo.setText(name);
393: }
394: }
395:
396: private void addWorkspaceTarget(IFile file) throws CoreException {
397: // If a saved workspace profile no longer exists in the workspace, skip it.
398: if (file != null && file.exists()) {
399: TargetModel model = new TargetModel();
400: model.load(new BufferedInputStream(file.getContents()),
401: false);
402: String value = model.getTarget().getName();
403: value = value + " [" + file.getFullPath().toString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
404: if (fProfileCombo.indexOf(value) == -1)
405: fProfileCombo.add(value, 1); //index 0 for "" (null target)
406: fProfileCombo.setText(value);
407: fContainsWorkspaceProfile = true;
408: }
409: }
410:
411: private void handleTargetBrowse() {
412: ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
413: getShell(), new WorkbenchLabelProvider(),
414: new WorkbenchContentProvider());
415:
416: dialog.setValidator(new FileValidator());
417: dialog.setAllowMultiple(false);
418: dialog
419: .setTitle(PDEUIMessages.TargetPlatformPreferencePage_FileSelectionTitle);
420: dialog
421: .setMessage(PDEUIMessages.TargetPlatformPreferencePage_FileSelectionMessage);
422: dialog.addFilter(new FileExtensionFilter("target")); //$NON-NLS-1$
423: dialog.setInput(PDEPlugin.getWorkspace().getRoot());
424: IFile target = getTargetFile();
425: if (target != null)
426: dialog.setInitialSelection(target);
427:
428: if (dialog.open() == Window.OK) {
429: IFile file = (IFile) dialog.getFirstResult();
430: try {
431: addWorkspaceTarget(file);
432: fLoadProfileButton.setEnabled(!fProfileCombo.getText()
433: .equals("")); //$NON-NLS-1$
434: } catch (CoreException e) {
435: }
436: }
437: }
438:
439: private IFile getTargetFile() {
440: if (!fContainsWorkspaceProfile
441: || !(fProfileCombo.getSelectionIndex() < (fProfileCombo
442: .getItemCount() - fElements.length)))
443: return null;
444: String target = fProfileCombo.getText().trim();
445: if (target.equals("")) //$NON-NLS-1$
446: return null;
447: int beginIndex = target.lastIndexOf('[');
448: target = target.substring(beginIndex + 1, target.length() - 1);
449: IPath targetPath = new Path(target);
450: if (targetPath.segmentCount() < 2)
451: return null;
452: return PDEPlugin.getWorkspace().getRoot().getFile(targetPath);
453: }
454:
455: private URL getExternalTargetURL() {
456: int offSet = fProfileCombo.getItemCount() - fElements.length;
457: if (offSet > fProfileCombo.getSelectionIndex())
458: return null;
459: IConfigurationElement elem = fElements[fProfileCombo
460: .getSelectionIndex()
461: - offSet];
462: String path = elem.getAttribute("definition"); //$NON-NLS-1$
463: String symbolicName = elem.getDeclaringExtension()
464: .getNamespaceIdentifier();
465: return TargetDefinitionManager.getResourceURL(symbolicName,
466: path);
467: }
468:
469: private String getTargetDescription() {
470: int offSet = fProfileCombo.getItemCount() - fElements.length;
471: if (offSet > fProfileCombo.getSelectionIndex())
472: return null;
473: IConfigurationElement elem = fElements[fProfileCombo
474: .getSelectionIndex()
475: - offSet];
476: IConfigurationElement[] children = elem
477: .getChildren("description"); //$NON-NLS-1$
478: if (children.length > 0)
479: return children[0].getValue();
480: return null;
481: }
482:
483: public void init(IWorkbench workbench) {
484: }
485:
486: private ITargetModel getTargetModel() {
487: InputStream stream = null;
488: try {
489: IFile file = getTargetFile();
490: String desc = null;
491: if (file != null)
492: stream = new BufferedInputStream(file.getContents());
493: if (stream == null) {
494: URL url = getExternalTargetURL();
495: desc = getTargetDescription();
496: if (url != null)
497: stream = new BufferedInputStream(url.openStream());
498: }
499:
500: if (stream != null) {
501: ITargetModel model = new TargetModel();
502: model.load(stream, false);
503: if (desc != null)
504: model.getTarget().setDescription(desc);
505: return model;
506: }
507: } catch (CoreException e) {
508: } catch (IOException e) {
509: } finally {
510: try {
511: if (stream != null)
512: stream.close();
513: } catch (IOException e) {
514: }
515: }
516: return null;
517: }
518:
519: private void handleLoadTargetProfile() {
520: if (fProfileCombo.getText().equals(""))return; //$NON-NLS-1$
521: ITargetModel model = getTargetModel();
522: if (model == null) {
523: MessageDialog
524: .openError(
525: getShell(),
526: PDEUIMessages.TargetPlatformPreferencePage_notFoundTitle,
527: PDEUIMessages.TargetPlatformPreferencePage_notFoundDescription);
528: return;
529: }
530:
531: if (!model.isLoaded()) {
532: MessageDialog
533: .openError(
534: getShell(),
535: PDEUIMessages.TargetPlatformPreferencePage_invalidTitle,
536: PDEUIMessages.TargetPlatformPreferencePage_invalidDescription);
537: return;
538: }
539:
540: ITarget target = model.getTarget();
541: ILocationInfo info = target.getLocationInfo();
542: String path;
543: if (info == null || info.useDefault()) {
544: path = TargetPlatform.getDefaultLocation();
545: } else {
546: try {
547: IStringVariableManager manager = VariablesPlugin
548: .getDefault().getStringVariableManager();
549: path = manager
550: .performStringSubstitution(info.getPath());
551: } catch (CoreException e) {
552: return;
553: }
554: }
555: if (!new Path(path).equals(new Path(fHomeText.getText()))
556: || !areAdditionalLocationsEqual(target)) {
557: fHomeText.setText(path);
558: ArrayList additional = new ArrayList();
559: IAdditionalLocation[] locations = target
560: .getAdditionalDirectories();
561: IStringVariableManager manager = VariablesPlugin
562: .getDefault().getStringVariableManager();
563: for (int i = 0; i < locations.length; i++) {
564: try {
565: additional.add(manager
566: .performStringSubstitution(locations[i]
567: .getPath()));
568: } catch (CoreException e) {
569: additional.add(locations[i]);
570: }
571: }
572: fPluginsTab.handleReload(additional);
573: }
574:
575: fPluginsTab.loadTargetProfile(target);
576: fEnvironmentTab.loadTargetProfile(target);
577: fArgumentsTab.loadTargetProfile(target);
578: fImplicitDependenciesTab.loadTargetProfile(target);
579: fSourceTab.loadTargetProfile(target);
580: }
581:
582: private boolean areAdditionalLocationsEqual(ITarget target) {
583: IAdditionalLocation[] addtionalLocs = target
584: .getAdditionalDirectories();
585: Preferences preferences = PDECore.getDefault()
586: .getPluginPreferences();
587: String value = preferences
588: .getString(ICoreConstants.ADDITIONAL_LOCATIONS);
589: StringTokenizer tokenzier = new StringTokenizer(value);
590: if (addtionalLocs.length != tokenzier.countTokens())
591: return false;
592: while (tokenzier.hasMoreTokens()) {
593: boolean found = false;
594: String location = tokenzier.nextToken();
595: for (int i = 0; i < addtionalLocs.length; i++) {
596: if (addtionalLocs[i].getPath().equals(location)) {
597: found = true;
598: break;
599: }
600: }
601: if (!found)
602: return false;
603: }
604: return true;
605: }
606:
607: public void performDefaults() {
608: fHomeText.setText(TargetPlatform.getDefaultLocation());
609: fPluginsTab.handleReload(new ArrayList());
610: fEnvironmentTab.performDefaults();
611: fArgumentsTab.performDefaults();
612: fImplicitDependenciesTab.performDefauls();
613: fSourceTab.performDefaults();
614: resetTargetProfile();
615: super .performDefaults();
616: }
617:
618: public boolean performOk() {
619: if (fNeedsReload
620: && !new Path(fOriginalText).equals(new Path(fHomeText
621: .getText()))) {
622: MessageDialog dialog = new MessageDialog(
623: getShell(),
624: PDEUIMessages.Preferences_TargetPlatformPage_title,
625: null,
626: PDEUIMessages.Preferences_TargetPlatformPage_question,
627: MessageDialog.QUESTION, new String[] {
628: IDialogConstants.YES_LABEL,
629: IDialogConstants.NO_LABEL }, 1);
630: if (dialog.open() == 1) {
631: getContainer().updateButtons();
632: return false;
633: }
634: fPluginsTab.handleReload(new ArrayList());
635: resetTargetProfile();
636: }
637: // if performOK is getting run in lieu of performApply, we need update the fOriginalText so if the user changes it back to the first state, we know we need to reload
638: fOriginalText = fHomeText.getText();
639: fEnvironmentTab.performOk();
640: fSourceTab.performOk();
641: fPluginsTab.performOk();
642: fArgumentsTab.performOk();
643: fImplicitDependenciesTab.performOk();
644: saveTarget();
645: return super .performOk();
646: }
647:
648: private void saveTarget() {
649: if (fProfileCombo.getText().equals("")) //$NON-NLS-1$
650: fPreferences.setValue(ICoreConstants.TARGET_PROFILE, ""); //$NON-NLS-1$
651: else if (fContainsWorkspaceProfile
652: && (fProfileCombo.getSelectionIndex() < (fProfileCombo
653: .getItemCount() - fElements.length))) {
654: String value = fProfileCombo.getText().trim();
655: int index = value.lastIndexOf('[');
656: value = value.substring(index + 1, value.length() - 1);
657: fPreferences.setValue(ICoreConstants.TARGET_PROFILE,
658: "${workspace_loc:" + value + "}"); //$NON-NLS-1$ //$NON-NLS-2$
659: } else {
660: int offSet = fProfileCombo.getItemCount()
661: - fElements.length;
662: IConfigurationElement elem = fElements[fProfileCombo
663: .getSelectionIndex()
664: - offSet];
665: fPreferences.setValue(ICoreConstants.TARGET_PROFILE,
666: "id:" + elem.getAttribute("id")); //$NON-NLS-1$ //$NON-NLS-2$
667: }
668: }
669:
670: public String[] getPlatformLocations() {
671: return fHomeText.getItems();
672: }
673:
674: public void resetNeedsReload() {
675: fNeedsReload = false;
676: String location = fHomeText.getText();
677: if (fHomeText.indexOf(location) == -1)
678: fHomeText.add(location, 0);
679: }
680:
681: public void resetTargetProfile() {
682: fProfileCombo.select(0);
683: fLoadProfileButton.setEnabled(false);
684: }
685:
686: public TargetSourceTab getSourceBlock() {
687: return fSourceTab;
688: }
689:
690: protected IPluginModelBase[] getCurrentModels() {
691: return fPluginsTab.getCurrentModels();
692: }
693:
694: protected PDEState getCurrentState() {
695: return fPluginsTab.getCurrentState();
696: }
697:
698: protected String[] getImplicitPlugins() {
699: return fImplicitDependenciesTab.getImplicitPlugins();
700: }
701:
702: private void openTargetWizard() {
703: NewTargetDefinitionWizard wizard = new NewTargetDefinitionWizard();
704: WizardDialog dialog = new WizardDialog(getShell(), wizard);
705: wizard.setInitialPath(new Path(new String()));
706: dialog.create();
707: SWTUtil.setDialogSize(dialog, 400, 450);
708: if (dialog.open() == Window.OK) {
709: IPath filePath = wizard.getFilePath();
710: IFile file = PDEPlugin.getWorkspace().getRoot().getFile(
711: filePath);
712: try {
713: addWorkspaceTarget(file);
714: } catch (CoreException e) {
715: }
716: }
717: }
718:
719: protected PDEExtensionRegistry getExtensionRegistry() {
720: return fPluginsTab.getCurrentExtensionRegistry();
721: }
722:
723: }
|