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.launcher;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.IConfigurationElement;
014: import org.eclipse.debug.core.ILaunchConfiguration;
015: import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
016: import org.eclipse.pde.internal.ui.PDEPlugin;
017: import org.eclipse.pde.internal.ui.PDEUIMessages;
018: import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
019: import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.events.ModifyEvent;
022: import org.eclipse.swt.events.ModifyListener;
023: import org.eclipse.swt.events.SelectionAdapter;
024: import org.eclipse.swt.events.SelectionEvent;
025: import org.eclipse.swt.layout.GridData;
026: import org.eclipse.swt.layout.GridLayout;
027: import org.eclipse.swt.widgets.Combo;
028: import org.eclipse.swt.widgets.Composite;
029: import org.eclipse.swt.widgets.Label;
030: import org.eclipse.swt.widgets.Spinner;
031:
032: public class OSGiFrameworkBlock {
033:
034: private Combo fDefaultAutoStart;
035: private Spinner fDefaultStartLevel;
036: private IConfigurationElement[] fConfigElements;
037: private Combo fLauncherCombo;
038: private Listener fListener;
039: private AbstractLauncherTab fTab;
040:
041: class Listener extends SelectionAdapter implements ModifyListener {
042:
043: public void widgetSelected(SelectionEvent e) {
044: fTab.updateLaunchConfigurationDialog();
045: }
046:
047: public void modifyText(ModifyEvent e) {
048: fTab.updateLaunchConfigurationDialog();
049: }
050: }
051:
052: public OSGiFrameworkBlock(AbstractLauncherTab tab) {
053: fTab = tab;
054: fConfigElements = PDEPlugin.getDefault()
055: .getOSGiFrameworkManager().getSortedFrameworks();
056: fListener = new Listener();
057: }
058:
059: public void createControl(Composite parent) {
060: Composite composite = new Composite(parent, SWT.NONE);
061: GridLayout layout = new GridLayout(6, false);
062: layout.marginHeight = layout.marginWidth = 0;
063: composite.setLayout(layout);
064: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
065: gd.horizontalSpan = 2;
066: composite.setLayoutData(gd);
067:
068: Label label = new Label(composite, SWT.NONE);
069: label.setText(PDEUIMessages.OSGiBundlesTab_frameworkLabel);
070: gd = new GridData();
071: gd.horizontalIndent = 5;
072: label.setLayoutData(gd);
073:
074: fLauncherCombo = new Combo(composite, SWT.READ_ONLY);
075: for (int i = 0; i < fConfigElements.length; i++)
076: fLauncherCombo.add(fConfigElements[i].getAttribute("name")); //$NON-NLS-1$
077: fLauncherCombo.addSelectionListener(fListener);
078:
079: label = new Label(composite, SWT.NONE);
080: gd = new GridData();
081: gd.horizontalIndent = 20;
082: label.setLayoutData(gd);
083: label.setText(PDEUIMessages.EquinoxPluginsTab_defaultStart);
084:
085: fDefaultStartLevel = new Spinner(composite, SWT.BORDER);
086: fDefaultStartLevel.setMinimum(1);
087: fDefaultStartLevel.addModifyListener(fListener);
088:
089: label = new Label(composite, SWT.NONE);
090: gd = new GridData();
091: gd.horizontalIndent = 20;
092: label.setLayoutData(gd);
093: label.setText(PDEUIMessages.EquinoxPluginsTab_defaultAuto);
094:
095: fDefaultAutoStart = new Combo(composite, SWT.BORDER
096: | SWT.READ_ONLY);
097: fDefaultAutoStart.setItems(new String[] {
098: Boolean.toString(true), Boolean.toString(false) });
099: fDefaultAutoStart.select(0);
100: fDefaultAutoStart.addSelectionListener(fListener);
101: }
102:
103: public void initializeFrom(ILaunchConfiguration config)
104: throws CoreException {
105: initializeFramework(config);
106: boolean auto = config.getAttribute(
107: IPDELauncherConstants.DEFAULT_AUTO_START, true);
108: fDefaultAutoStart.setText(Boolean.toString(auto));
109: int level = config.getAttribute(
110: IPDELauncherConstants.DEFAULT_START_LEVEL, 4);
111: fDefaultStartLevel.setSelection(level);
112: }
113:
114: private void initializeFramework(ILaunchConfiguration config)
115: throws CoreException {
116: OSGiFrameworkManager manager = PDEPlugin.getDefault()
117: .getOSGiFrameworkManager();
118: String id = config.getAttribute(
119: IPDELauncherConstants.OSGI_FRAMEWORK_ID, manager
120: .getDefaultFramework());
121:
122: for (int i = 0; i < fConfigElements.length; i++) {
123: if (id.equals(fConfigElements[i]
124: .getAttribute(OSGiFrameworkManager.ATT_ID))) {
125: fLauncherCombo.select(i);
126: return;
127: }
128: }
129: if (fLauncherCombo.getItemCount() > 0)
130: fLauncherCombo.select(0);
131: }
132:
133: public void performApply(ILaunchConfigurationWorkingCopy config) {
134: config.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START,
135: Boolean.toString(true).equals(
136: fDefaultAutoStart.getText()));
137: config.setAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL,
138: fDefaultStartLevel.getSelection());
139:
140: int index = fLauncherCombo.getSelectionIndex();
141: String id = index > -1 ? fConfigElements[index]
142: .getAttribute(OSGiFrameworkManager.ATT_ID) : null;
143: OSGiFrameworkManager manager = PDEPlugin.getDefault()
144: .getOSGiFrameworkManager();
145:
146: // no need to persist the default OSGi framework
147: if (manager.getDefaultFramework().equals(id))
148: id = null;
149: config
150: .setAttribute(IPDELauncherConstants.OSGI_FRAMEWORK_ID,
151: id);
152: }
153:
154: public int getDefaultStartLevel() {
155: return fDefaultStartLevel.getSelection();
156: }
157: }
|