KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > target > TargetProfileWindow


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.editor.target;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.core.variables.VariablesPlugin;
16 import org.eclipse.jdt.launching.JavaRuntime;
17 import org.eclipse.jface.viewers.ArrayContentProvider;
18 import org.eclipse.jface.viewers.TableViewer;
19 import org.eclipse.jface.window.ApplicationWindow;
20 import org.eclipse.pde.core.plugin.TargetPlatform;
21 import org.eclipse.pde.internal.core.itarget.IAdditionalLocation;
22 import org.eclipse.pde.internal.core.itarget.IArgumentsInfo;
23 import org.eclipse.pde.internal.core.itarget.IEnvironmentInfo;
24 import org.eclipse.pde.internal.core.itarget.IImplicitDependenciesInfo;
25 import org.eclipse.pde.internal.core.itarget.ILocationInfo;
26 import org.eclipse.pde.internal.core.itarget.ITarget;
27 import org.eclipse.pde.internal.core.itarget.ITargetFeature;
28 import org.eclipse.pde.internal.core.itarget.ITargetJRE;
29 import org.eclipse.pde.internal.core.itarget.ITargetModel;
30 import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
31 import org.eclipse.pde.internal.ui.PDEPlugin;
32 import org.eclipse.pde.internal.ui.PDEUIMessages;
33 import org.eclipse.pde.internal.ui.parts.FormEntry;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.custom.CTabFolder;
36 import org.eclipse.swt.custom.CTabItem;
37 import org.eclipse.swt.graphics.Color;
38 import org.eclipse.swt.layout.GridData;
39 import org.eclipse.swt.layout.GridLayout;
40 import org.eclipse.swt.widgets.Composite;
41 import org.eclipse.swt.widgets.Control;
42 import org.eclipse.swt.widgets.Label;
43 import org.eclipse.swt.widgets.Shell;
44 import org.eclipse.ui.forms.IFormColors;
45 import org.eclipse.ui.forms.widgets.FormToolkit;
46 import org.eclipse.ui.forms.widgets.ScrolledForm;
47
48 public class TargetProfileWindow extends ApplicationWindow {
49
50     protected ITargetModel fTargetModel;
51     private FormToolkit fToolkit;
52     private String JavaDoc fTargetName;
53
54     public TargetProfileWindow(Shell parentShell, ITargetModel model, String JavaDoc targetName) {
55         super(parentShell);
56         setShellStyle(SWT.MAX | SWT.RESIZE | SWT.CLOSE | SWT.APPLICATION_MODAL);
57         fTargetModel = model;
58         fTargetName = targetName;
59     }
60     
61     public void create() {
62         super.create();
63         getShell().setText(PDEUIMessages.TargetProfileWindow_title);
64         getShell().setSize(500, 300);
65     }
66     
67     protected Control createContents(Composite parent) {
68         fToolkit = new FormToolkit(parent.getDisplay());
69         CTabFolder folder = new CTabFolder(parent, SWT.NONE);
70         folder.setLayout(new GridLayout());
71         fToolkit.adapt(folder, true, true);
72         fToolkit.adapt(parent);
73         fToolkit.getColors().initializeSectionToolBarColors();
74         Color selectedColor = fToolkit.getColors().getColor(IFormColors.TB_BG);
75         folder.setSelectionBackground(new Color[] { selectedColor,
76                 fToolkit.getColors().getBackground() },
77                 new int[] { 100 }, true);
78         
79         CTabItem item = new CTabItem(folder, SWT.NONE);
80         item.setControl(createDefinitionTab(folder, fToolkit));
81         item.setText(PDEUIMessages.TargetProfileWindow_definition);
82         
83         ITarget target = fTargetModel.getTarget();
84
85         ITargetPlugin[] plugins = target.getPlugins();
86         if (!target.useAllPlugins() && plugins.length > 0) {
87             item = new CTabItem(folder, SWT.NONE);
88             item.setControl(createTabularTab(folder, fToolkit, plugins));
89             item.setText(PDEUIMessages.TargetProfileWindow_plugins);
90         }
91         
92         ITargetFeature[] features = target.getFeatures();
93         if (!target.useAllPlugins() && features.length > 0) {
94             item = new CTabItem(folder, SWT.NONE);
95             item.setControl(createTabularTab(folder, fToolkit, features));
96             item.setText(PDEUIMessages.TargetProfileWindow_features);
97         }
98         
99         item = new CTabItem(folder, SWT.NONE);
100         item.setControl(createEnvironmentTab(folder, fToolkit));
101         item.setText(PDEUIMessages.TargetProfileWindow_environment);
102         
103         IArgumentsInfo argInfo = target.getArguments();
104         if (argInfo != null) {
105             item = new CTabItem(folder, SWT.NONE);
106             item.setControl(createArgumentsTab(folder, fToolkit, argInfo));
107             item.setText(PDEUIMessages.TargetProfileWindow_launching);
108         }
109         
110         IImplicitDependenciesInfo info = target.getImplicitPluginsInfo();
111         if (info != null) {
112             item = new CTabItem(folder, SWT.NONE);
113             item.setControl(createTabularTab(folder, fToolkit, info.getPlugins()));
114             item.setText(PDEUIMessages.TargetProfileWindow_implicit);
115         }
116         
117         return folder;
118     }
119     
120     private Control createDefinitionTab(Composite parent, FormToolkit toolkit) {
121         ScrolledForm form = toolkit.createScrolledForm(parent);
122         Composite body = form.getBody();
123         GridLayout layout = new GridLayout(2, false);
124         layout.marginWidth = layout.marginHeight = 5;
125         body.setLayout(layout);
126         
127         ITarget target = fTargetModel.getTarget();
128         createEntry(body, toolkit, PDEUIMessages.TargetDefinitionSection_name, fTargetName);
129         createEntry(body, toolkit, PDEUIMessages.TargetDefinitionSection_targetLocation, getLocation(target));
130         
131         IAdditionalLocation[] locs = target.getAdditionalDirectories();
132         if (locs.length > 0) {
133             Label label = toolkit.createLabel(body, PDEUIMessages.TargetProfileWindow_additionalLocations);
134             label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
135             label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
136             createTable(body, toolkit, locs);
137         }
138         
139         String JavaDoc desc = target.getDescription();
140         if (desc != null) {
141             FormEntry entry = createEntry(body, toolkit, PDEUIMessages.TargetProfileWindow_targetDescription, desc, SWT.WRAP|SWT.V_SCROLL);
142             GridData gd = new GridData(GridData.FILL_BOTH);
143             gd.widthHint = 200;
144             entry.getText().setLayoutData(gd);
145             entry.getLabel().setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
146         }
147         
148         toolkit.paintBordersFor(form.getBody());
149         return form;
150     }
151
152     private Control createEnvironmentTab(Composite parent, FormToolkit toolkit) {
153         ScrolledForm form = toolkit.createScrolledForm(parent);
154         Composite body = form.getBody();
155         GridLayout layout = new GridLayout(2, false);
156         layout.marginWidth = layout.marginHeight = 5;
157         body.setLayout(layout);
158         
159         ITarget target = fTargetModel.getTarget();
160         IEnvironmentInfo info = target.getEnvironment();
161         
162         String JavaDoc os = info == null ? Platform.getOS() : info.getDisplayOS();
163         createEntry(body, toolkit, PDEUIMessages.EnvironmentSection_operationSystem, os);
164         
165         String JavaDoc ws = info == null ? Platform.getWS() : info.getDisplayWS();
166         createEntry(body, toolkit, PDEUIMessages.EnvironmentSection_windowingSystem, ws);
167         
168         String JavaDoc arch = info == null ? Platform.getOSArch() : info.getDisplayArch();
169         createEntry(body, toolkit, PDEUIMessages.EnvironmentSection_architecture, arch);
170         
171         String JavaDoc nl = info == null ? Platform.getNL() : info.getDisplayNL();
172         createEntry(body, toolkit, PDEUIMessages.EnvironmentSection_locale, nl);
173         
174         ITargetJRE jreInfo = target.getTargetJREInfo();
175         String JavaDoc jre = jreInfo == null ? JavaRuntime.getDefaultVMInstall().getName() : jreInfo.getCompatibleJRE();
176         createEntry(body, toolkit, PDEUIMessages.TargetProfileWindow_jre, jre);
177         
178         toolkit.paintBordersFor(form.getBody());
179         return form;
180     }
181     
182     private Control createTabularTab(Composite parent, FormToolkit toolkit, Object JavaDoc[] objects) {
183         ScrolledForm form = toolkit.createScrolledForm(parent);
184         Composite body = form.getBody();
185         GridLayout layout = new GridLayout();
186         layout.marginWidth = layout.marginHeight = 5;
187         body.setLayout(layout);
188
189         createTable(body, toolkit, objects);
190         
191         toolkit.paintBordersFor(form.getBody());
192         return form;
193     }
194     
195     private Control createTable(Composite parent, FormToolkit toolkit, Object JavaDoc[] objects) {
196         int style = SWT.H_SCROLL | SWT.V_SCROLL | toolkit.getBorderStyle();
197
198         TableViewer tableViewer = new TableViewer(parent, style);
199         tableViewer.setContentProvider(new ArrayContentProvider());
200         tableViewer.setLabelProvider(PDEPlugin.getDefault().getLabelProvider());
201         tableViewer.setInput(objects);
202         tableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
203         return tableViewer.getControl();
204     }
205
206     private Control createArgumentsTab(Composite parent, FormToolkit toolkit, IArgumentsInfo info) {
207         ScrolledForm form = toolkit.createScrolledForm(parent);
208         Composite body = form.getBody();
209         GridLayout layout = new GridLayout();
210         layout.marginWidth = layout.marginHeight = 5;
211         body.setLayout(layout);
212         
213         FormEntry entry = createEntry(body, toolkit, PDEUIMessages.TargetProfileWindow_program, info.getProgramArguments());
214         entry.getText().setLayoutData(new GridData(GridData.FILL_BOTH));
215         entry = createEntry(body, toolkit, PDEUIMessages.TargetProfileWindow_vm, info.getVMArguments());
216         entry.getText().setLayoutData(new GridData(GridData.FILL_BOTH));
217         
218         toolkit.paintBordersFor(form.getBody());
219         return form;
220     }
221     
222     private FormEntry createEntry(Composite client, FormToolkit toolkit, String JavaDoc text, String JavaDoc value) {
223         return createEntry(client, toolkit, text, value, SWT.NONE);
224     }
225     
226     private FormEntry createEntry(Composite client, FormToolkit toolkit, String JavaDoc text, String JavaDoc value, int style) {
227         FormEntry entry = new FormEntry(client, toolkit, text, style);
228         entry.setValue(value);
229         entry.setEditable(false);
230         return entry;
231     }
232     
233     private String JavaDoc getLocation(ITarget target) {
234         ILocationInfo info = target.getLocationInfo();
235         if (info == null || info.useDefault())
236             return TargetPlatform.getDefaultLocation();
237         try {
238             return VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(info.getPath());
239         } catch (CoreException e) {
240         }
241         return ""; //$NON-NLS-1$
242
}
243     
244     public boolean close() {
245         fToolkit.dispose();
246         return super.close();
247     }
248
249 }
250
Popular Tags