KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > OSGiFrameworkBlock


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.launcher;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IConfigurationElement;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17 import org.eclipse.pde.internal.ui.PDEPlugin;
18 import org.eclipse.pde.internal.ui.PDEUIMessages;
19 import org.eclipse.pde.ui.launcher.AbstractLauncherTab;
20 import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.ModifyEvent;
23 import org.eclipse.swt.events.ModifyListener;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Combo;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.swt.widgets.Spinner;
32
33 public class OSGiFrameworkBlock {
34     
35     private Combo fDefaultAutoStart;
36     private Spinner fDefaultStartLevel;
37     private IConfigurationElement[] fConfigElements;
38     private Combo fLauncherCombo;
39     private Listener fListener;
40     private AbstractLauncherTab fTab;
41     
42     class Listener extends SelectionAdapter implements ModifyListener{
43         
44         public void widgetSelected(SelectionEvent e) {
45             fTab.updateLaunchConfigurationDialog();
46         }
47
48         public void modifyText(ModifyEvent e) {
49             fTab.updateLaunchConfigurationDialog();
50         }
51     }
52     
53     public OSGiFrameworkBlock(AbstractLauncherTab tab) {
54         fTab = tab;
55         fConfigElements = PDEPlugin.getDefault().getOSGiFrameworkManager().getSortedFrameworks();
56         fListener = new Listener();
57     }
58     
59     public void createControl(Composite parent) {
60         Composite composite = new Composite(parent, SWT.NONE);
61         GridLayout layout = new GridLayout(6, false);
62         layout.marginHeight = layout.marginWidth = 0;
63         composite.setLayout(layout);
64         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
65         gd.horizontalSpan = 2;
66         composite.setLayoutData(gd);
67
68         Label label = new Label(composite, SWT.NONE);
69         label.setText(PDEUIMessages.OSGiBundlesTab_frameworkLabel);
70         gd = new GridData();
71         gd.horizontalIndent = 5;
72         label.setLayoutData(gd);
73         
74         fLauncherCombo = new Combo(composite, SWT.READ_ONLY);
75         for (int i = 0; i < fConfigElements.length; i++)
76             fLauncherCombo.add(fConfigElements[i].getAttribute("name")); //$NON-NLS-1$
77
fLauncherCombo.addSelectionListener(fListener);
78         
79         label = new Label(composite, SWT.NONE);
80         gd = new GridData();
81         gd.horizontalIndent = 20;
82         label.setLayoutData(gd);
83         label.setText(PDEUIMessages.EquinoxPluginsTab_defaultStart);
84
85         fDefaultStartLevel = new Spinner(composite, SWT.BORDER);
86         fDefaultStartLevel.setMinimum(1);
87         fDefaultStartLevel.addModifyListener(fListener);
88
89         label = new Label(composite, SWT.NONE);
90         gd = new GridData();
91         gd.horizontalIndent = 20;
92         label.setLayoutData(gd);
93         label.setText(PDEUIMessages.EquinoxPluginsTab_defaultAuto);
94
95         fDefaultAutoStart = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
96         fDefaultAutoStart.setItems(new String JavaDoc[] {Boolean.toString(true), Boolean.toString(false)});
97         fDefaultAutoStart.select(0);
98         fDefaultAutoStart.addSelectionListener(fListener);
99     }
100     
101     public void initializeFrom(ILaunchConfiguration config) throws CoreException {
102         initializeFramework(config);
103         boolean auto = config.getAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, true);
104         fDefaultAutoStart.setText(Boolean.toString(auto));
105         int level = config.getAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4);
106         fDefaultStartLevel.setSelection(level);
107     }
108     
109     private void initializeFramework(ILaunchConfiguration config) throws CoreException {
110         OSGiFrameworkManager manager = PDEPlugin.getDefault().getOSGiFrameworkManager();
111         String JavaDoc id = config.getAttribute(IPDELauncherConstants.OSGI_FRAMEWORK_ID,
112                                         manager.getDefaultFramework());
113         
114         for (int i = 0; i < fConfigElements.length; i++) {
115             if (id.equals(fConfigElements[i].getAttribute(OSGiFrameworkManager.ATT_ID))){
116                 fLauncherCombo.select(i);
117                 return;
118             }
119         }
120         if (fLauncherCombo.getItemCount() > 0)
121             fLauncherCombo.select(0);
122     }
123     
124     public void performApply(ILaunchConfigurationWorkingCopy config) {
125         config.setAttribute(IPDELauncherConstants.DEFAULT_AUTO_START,
126                 Boolean.toString(true).equals(fDefaultAutoStart.getText()));
127         config.setAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, fDefaultStartLevel.getSelection());
128         
129         int index = fLauncherCombo.getSelectionIndex();
130         String JavaDoc id = index > -1 ? fConfigElements[index].getAttribute(OSGiFrameworkManager.ATT_ID) : null;
131         OSGiFrameworkManager manager = PDEPlugin.getDefault().getOSGiFrameworkManager();
132
133         // no need to persist the default OSGi framework
134
if (manager.getDefaultFramework().equals(id))
135             id = null;
136         config.setAttribute(IPDELauncherConstants.OSGI_FRAMEWORK_ID, id);
137     }
138     
139     public int getDefaultStartLevel() {
140         return fDefaultStartLevel.getSelection();
141     }
142 }
143
Popular Tags