001: /*******************************************************************************
002: * Copyright (c) 2006, 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 org.eclipse.core.runtime.IConfigurationElement;
013: import org.eclipse.jface.dialogs.Dialog;
014: import org.eclipse.jface.preference.IPreferenceStore;
015: import org.eclipse.jface.preference.PreferencePage;
016: import org.eclipse.jface.viewers.ArrayContentProvider;
017: import org.eclipse.jface.viewers.ISelectionChangedListener;
018: import org.eclipse.jface.viewers.IStructuredSelection;
019: import org.eclipse.jface.viewers.LabelProvider;
020: import org.eclipse.jface.viewers.SelectionChangedEvent;
021: import org.eclipse.jface.viewers.TableViewer;
022: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
023: import org.eclipse.pde.internal.core.PDECore;
024: import org.eclipse.pde.internal.ui.IHelpContextIds;
025: import org.eclipse.pde.internal.ui.IPreferenceConstants;
026: import org.eclipse.pde.internal.ui.PDEPlugin;
027: import org.eclipse.pde.internal.ui.PDEPluginImages;
028: import org.eclipse.pde.internal.ui.PDEUIMessages;
029: import org.eclipse.pde.internal.ui.launcher.OSGiFrameworkManager;
030: import org.eclipse.pde.internal.ui.search.ShowDescriptionAction;
031: import org.eclipse.pde.internal.ui.util.SWTUtil;
032: import org.eclipse.swt.SWT;
033: import org.eclipse.swt.events.SelectionAdapter;
034: import org.eclipse.swt.events.SelectionEvent;
035: import org.eclipse.swt.graphics.Image;
036: import org.eclipse.swt.layout.GridData;
037: import org.eclipse.swt.layout.GridLayout;
038: import org.eclipse.swt.widgets.Button;
039: import org.eclipse.swt.widgets.Composite;
040: import org.eclipse.swt.widgets.Control;
041: import org.eclipse.swt.widgets.Display;
042: import org.eclipse.swt.widgets.Link;
043: import org.eclipse.ui.IWorkbench;
044: import org.eclipse.ui.IWorkbenchPreferencePage;
045: import org.eclipse.ui.PlatformUI;
046:
047: public class OSGiFrameworkPreferencePage extends PreferencePage
048: implements IWorkbenchPreferencePage {
049:
050: class FrameworkLabelProvider extends LabelProvider {
051: public Image getImage(Object element) {
052: return PDEPluginImages.get(PDEPluginImages.OBJ_DESC_BUNDLE);
053: }
054:
055: public String getText(Object element) {
056: if (element instanceof IConfigurationElement) {
057: String name = ((IConfigurationElement) element)
058: .getAttribute(OSGiFrameworkManager.ATT_NAME);
059: String id = ((IConfigurationElement) element)
060: .getAttribute(OSGiFrameworkManager.ATT_ID);
061: return fDefaultFramework.equals(id) ? name
062: + " " + PDEUIMessages.OSGiFrameworkPreferencePage_default : name; //$NON-NLS-1$
063: }
064: return super .getText(element);
065: }
066: }
067:
068: private TableViewer fTableViewer;
069: private Button fSetDefaultButton;
070: private String fDefaultFramework;
071:
072: public OSGiFrameworkPreferencePage() {
073: setDefaultFramework();
074: }
075:
076: private void setDefaultFramework() {
077: IPreferenceStore store = PDEPlugin.getDefault()
078: .getPreferenceStore();
079: fDefaultFramework = store
080: .getString(IPreferenceConstants.DEFAULT_OSGI_FRAMEOWRK);
081: }
082:
083: protected Control createContents(Composite parent) {
084: Composite container = new Composite(parent, SWT.NULL);
085: GridLayout layout = new GridLayout();
086: layout.numColumns = 2;
087: layout.verticalSpacing = 10;
088: container.setLayout(layout);
089:
090: Link text = new Link(container, SWT.WRAP);
091: text
092: .setText(PDEUIMessages.OSGiFrameworkPreferencePage_installed);
093: GridData gd = new GridData();
094: gd.horizontalSpan = 2;
095: text.setLayoutData(gd);
096: text.addSelectionListener(new SelectionAdapter() {
097: public void widgetSelected(SelectionEvent e) {
098: IPluginExtensionPoint point = PDECore.getDefault()
099: .getExtensionsRegistry().findExtensionPoint(
100: OSGiFrameworkManager.POINT_ID);
101: if (point != null) {
102: new ShowDescriptionAction(point, true).run();
103: } else {
104: Display.getDefault().beep();
105: }
106: }
107: });
108:
109: fTableViewer = new TableViewer(container, SWT.BORDER);
110: fTableViewer.getTable().setLayoutData(
111: new GridData(GridData.FILL_BOTH));
112: fTableViewer.setContentProvider(new ArrayContentProvider());
113: fTableViewer.setLabelProvider(new FrameworkLabelProvider());
114: fTableViewer.setInput(PDEPlugin.getDefault()
115: .getOSGiFrameworkManager().getSortedFrameworks());
116: fTableViewer
117: .addSelectionChangedListener(new ISelectionChangedListener() {
118: public void selectionChanged(
119: SelectionChangedEvent event) {
120: IStructuredSelection ssel = (IStructuredSelection) event
121: .getSelection();
122: String id = ((IConfigurationElement) ssel
123: .getFirstElement()).getAttribute("id"); //$NON-NLS-1$
124: fSetDefaultButton.setEnabled(ssel.size() == 1
125: && !fDefaultFramework.equals(id));
126: }
127: });
128:
129: Composite buttonContainer = new Composite(container, SWT.NONE);
130: layout = new GridLayout();
131: layout.marginWidth = layout.marginHeight = 0;
132: buttonContainer.setLayout(layout);
133: buttonContainer.setLayoutData(new GridData(
134: GridData.FILL_VERTICAL));
135:
136: fSetDefaultButton = new Button(buttonContainer, SWT.PUSH);
137: fSetDefaultButton
138: .setText(PDEUIMessages.OSGiFrameworkPreferencePage_setAs);
139: fSetDefaultButton.setLayoutData(new GridData(GridData.FILL
140: | GridData.VERTICAL_ALIGN_BEGINNING));
141: SWTUtil.setButtonDimensionHint(fSetDefaultButton);
142: fSetDefaultButton.addSelectionListener(new SelectionAdapter() {
143: public void widgetSelected(SelectionEvent e) {
144: IStructuredSelection ssel = (IStructuredSelection) fTableViewer
145: .getSelection();
146: IConfigurationElement element = (IConfigurationElement) ssel
147: .getFirstElement();
148: fDefaultFramework = element
149: .getAttribute(OSGiFrameworkManager.ATT_ID);
150: fTableViewer.refresh();
151: fSetDefaultButton.setEnabled(false);
152: }
153: });
154: fSetDefaultButton.setEnabled(false);
155: Dialog.applyDialogFont(parent);
156: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
157: IHelpContextIds.OSGI_PREFERENCE_PAGE);
158: return container;
159: }
160:
161: public boolean performOk() {
162: IPreferenceStore store = PDEPlugin.getDefault()
163: .getPreferenceStore();
164: store.setValue(IPreferenceConstants.DEFAULT_OSGI_FRAMEOWRK,
165: fDefaultFramework);
166: PDEPlugin.getDefault().savePluginPreferences();
167: return super .performOk();
168: }
169:
170: protected void performDefaults() {
171: setDefaultFramework();
172: fTableViewer.refresh();
173: }
174:
175: public void init(IWorkbench workbench) {
176: }
177:
178: }
|