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.editor.target;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.core.runtime.Platform;
014: import org.eclipse.core.variables.VariablesPlugin;
015: import org.eclipse.jdt.launching.JavaRuntime;
016: import org.eclipse.jface.viewers.ArrayContentProvider;
017: import org.eclipse.jface.viewers.TableViewer;
018: import org.eclipse.jface.window.ApplicationWindow;
019: import org.eclipse.pde.core.plugin.TargetPlatform;
020: import org.eclipse.pde.internal.core.itarget.IAdditionalLocation;
021: import org.eclipse.pde.internal.core.itarget.IArgumentsInfo;
022: import org.eclipse.pde.internal.core.itarget.IEnvironmentInfo;
023: import org.eclipse.pde.internal.core.itarget.IImplicitDependenciesInfo;
024: import org.eclipse.pde.internal.core.itarget.ILocationInfo;
025: import org.eclipse.pde.internal.core.itarget.ITarget;
026: import org.eclipse.pde.internal.core.itarget.ITargetFeature;
027: import org.eclipse.pde.internal.core.itarget.ITargetJRE;
028: import org.eclipse.pde.internal.core.itarget.ITargetModel;
029: import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
030: import org.eclipse.pde.internal.ui.PDEPlugin;
031: import org.eclipse.pde.internal.ui.PDEUIMessages;
032: import org.eclipse.pde.internal.ui.parts.FormEntry;
033: import org.eclipse.swt.SWT;
034: import org.eclipse.swt.custom.CTabFolder;
035: import org.eclipse.swt.custom.CTabItem;
036: import org.eclipse.swt.graphics.Color;
037: import org.eclipse.swt.layout.GridData;
038: import org.eclipse.swt.layout.GridLayout;
039: import org.eclipse.swt.widgets.Composite;
040: import org.eclipse.swt.widgets.Control;
041: import org.eclipse.swt.widgets.Label;
042: import org.eclipse.swt.widgets.Shell;
043: import org.eclipse.ui.forms.IFormColors;
044: import org.eclipse.ui.forms.widgets.FormToolkit;
045: import org.eclipse.ui.forms.widgets.ScrolledForm;
046:
047: public class TargetProfileWindow extends ApplicationWindow {
048:
049: protected ITargetModel fTargetModel;
050: private FormToolkit fToolkit;
051: private String fTargetName;
052:
053: public TargetProfileWindow(Shell parentShell, ITargetModel model,
054: String targetName) {
055: super (parentShell);
056: setShellStyle(SWT.MAX | SWT.RESIZE | SWT.CLOSE
057: | SWT.APPLICATION_MODAL);
058: fTargetModel = model;
059: fTargetName = targetName;
060: }
061:
062: public void create() {
063: super .create();
064: getShell().setText(PDEUIMessages.TargetProfileWindow_title);
065: getShell().setSize(500, 300);
066: }
067:
068: protected Control createContents(Composite parent) {
069: fToolkit = new FormToolkit(parent.getDisplay());
070: CTabFolder folder = new CTabFolder(parent, SWT.NONE);
071: folder.setLayout(new GridLayout());
072: fToolkit.adapt(folder, true, true);
073: fToolkit.adapt(parent);
074: fToolkit.getColors().initializeSectionToolBarColors();
075: Color selectedColor = fToolkit.getColors().getColor(
076: IFormColors.TB_BG);
077: folder.setSelectionBackground(new Color[] { selectedColor,
078: fToolkit.getColors().getBackground() },
079: new int[] { 100 }, true);
080:
081: CTabItem item = new CTabItem(folder, SWT.NONE);
082: item.setControl(createDefinitionTab(folder, fToolkit));
083: item.setText(PDEUIMessages.TargetProfileWindow_definition);
084:
085: ITarget target = fTargetModel.getTarget();
086:
087: ITargetPlugin[] plugins = target.getPlugins();
088: if (!target.useAllPlugins() && plugins.length > 0) {
089: item = new CTabItem(folder, SWT.NONE);
090: item
091: .setControl(createTabularTab(folder, fToolkit,
092: plugins));
093: item.setText(PDEUIMessages.TargetProfileWindow_plugins);
094: }
095:
096: ITargetFeature[] features = target.getFeatures();
097: if (!target.useAllPlugins() && features.length > 0) {
098: item = new CTabItem(folder, SWT.NONE);
099: item
100: .setControl(createTabularTab(folder, fToolkit,
101: features));
102: item.setText(PDEUIMessages.TargetProfileWindow_features);
103: }
104:
105: item = new CTabItem(folder, SWT.NONE);
106: item.setControl(createEnvironmentTab(folder, fToolkit));
107: item.setText(PDEUIMessages.TargetProfileWindow_environment);
108:
109: IArgumentsInfo argInfo = target.getArguments();
110: if (argInfo != null) {
111: item = new CTabItem(folder, SWT.NONE);
112: item.setControl(createArgumentsTab(folder, fToolkit,
113: argInfo));
114: item.setText(PDEUIMessages.TargetProfileWindow_launching);
115: }
116:
117: IImplicitDependenciesInfo info = target
118: .getImplicitPluginsInfo();
119: if (info != null) {
120: item = new CTabItem(folder, SWT.NONE);
121: item.setControl(createTabularTab(folder, fToolkit, info
122: .getPlugins()));
123: item.setText(PDEUIMessages.TargetProfileWindow_implicit);
124: }
125:
126: return folder;
127: }
128:
129: private Control createDefinitionTab(Composite parent,
130: FormToolkit toolkit) {
131: ScrolledForm form = toolkit.createScrolledForm(parent);
132: Composite body = form.getBody();
133: GridLayout layout = new GridLayout(2, false);
134: layout.marginWidth = layout.marginHeight = 5;
135: body.setLayout(layout);
136:
137: ITarget target = fTargetModel.getTarget();
138: createEntry(body, toolkit,
139: PDEUIMessages.TargetDefinitionSection_name, fTargetName);
140: createEntry(body, toolkit,
141: PDEUIMessages.TargetDefinitionSection_targetLocation,
142: getLocation(target));
143:
144: IAdditionalLocation[] locs = target.getAdditionalDirectories();
145: if (locs.length > 0) {
146: Label label = toolkit
147: .createLabel(
148: body,
149: PDEUIMessages.TargetProfileWindow_additionalLocations);
150: label.setForeground(toolkit.getColors().getColor(
151: IFormColors.TITLE));
152: label.setLayoutData(new GridData(
153: GridData.VERTICAL_ALIGN_BEGINNING));
154: createTable(body, toolkit, locs);
155: }
156:
157: String desc = target.getDescription();
158: if (desc != null) {
159: FormEntry entry = createEntry(
160: body,
161: toolkit,
162: PDEUIMessages.TargetProfileWindow_targetDescription,
163: desc, SWT.WRAP | SWT.V_SCROLL);
164: GridData gd = new GridData(GridData.FILL_BOTH);
165: gd.widthHint = 200;
166: entry.getText().setLayoutData(gd);
167: entry.getLabel().setLayoutData(
168: new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
169: }
170:
171: toolkit.paintBordersFor(form.getBody());
172: return form;
173: }
174:
175: private Control createEnvironmentTab(Composite parent,
176: FormToolkit toolkit) {
177: ScrolledForm form = toolkit.createScrolledForm(parent);
178: Composite body = form.getBody();
179: GridLayout layout = new GridLayout(2, false);
180: layout.marginWidth = layout.marginHeight = 5;
181: body.setLayout(layout);
182:
183: ITarget target = fTargetModel.getTarget();
184: IEnvironmentInfo info = target.getEnvironment();
185:
186: String os = info == null ? Platform.getOS() : info
187: .getDisplayOS();
188: createEntry(body, toolkit,
189: PDEUIMessages.EnvironmentSection_operationSystem, os);
190:
191: String ws = info == null ? Platform.getWS() : info
192: .getDisplayWS();
193: createEntry(body, toolkit,
194: PDEUIMessages.EnvironmentSection_windowingSystem, ws);
195:
196: String arch = info == null ? Platform.getOSArch() : info
197: .getDisplayArch();
198: createEntry(body, toolkit,
199: PDEUIMessages.EnvironmentSection_architecture, arch);
200:
201: String nl = info == null ? Platform.getNL() : info
202: .getDisplayNL();
203: createEntry(body, toolkit,
204: PDEUIMessages.EnvironmentSection_locale, nl);
205:
206: ITargetJRE jreInfo = target.getTargetJREInfo();
207: String jre = jreInfo == null ? JavaRuntime
208: .getDefaultVMInstall().getName() : jreInfo
209: .getCompatibleJRE();
210: createEntry(body, toolkit,
211: PDEUIMessages.TargetProfileWindow_jre, jre);
212:
213: toolkit.paintBordersFor(form.getBody());
214: return form;
215: }
216:
217: private Control createTabularTab(Composite parent,
218: FormToolkit toolkit, Object[] objects) {
219: ScrolledForm form = toolkit.createScrolledForm(parent);
220: Composite body = form.getBody();
221: GridLayout layout = new GridLayout();
222: layout.marginWidth = layout.marginHeight = 5;
223: body.setLayout(layout);
224:
225: createTable(body, toolkit, objects);
226:
227: toolkit.paintBordersFor(form.getBody());
228: return form;
229: }
230:
231: private Control createTable(Composite parent, FormToolkit toolkit,
232: Object[] objects) {
233: int style = SWT.H_SCROLL | SWT.V_SCROLL
234: | toolkit.getBorderStyle();
235:
236: TableViewer tableViewer = new TableViewer(parent, style);
237: tableViewer.setContentProvider(new ArrayContentProvider());
238: tableViewer.setLabelProvider(PDEPlugin.getDefault()
239: .getLabelProvider());
240: tableViewer.setInput(objects);
241: tableViewer.getControl().setLayoutData(
242: new GridData(GridData.FILL_BOTH));
243: return tableViewer.getControl();
244: }
245:
246: private Control createArgumentsTab(Composite parent,
247: FormToolkit toolkit, IArgumentsInfo info) {
248: ScrolledForm form = toolkit.createScrolledForm(parent);
249: Composite body = form.getBody();
250: GridLayout layout = new GridLayout();
251: layout.marginWidth = layout.marginHeight = 5;
252: body.setLayout(layout);
253:
254: FormEntry entry = createEntry(body, toolkit,
255: PDEUIMessages.TargetProfileWindow_program, info
256: .getProgramArguments());
257: entry.getText().setLayoutData(new GridData(GridData.FILL_BOTH));
258: entry = createEntry(body, toolkit,
259: PDEUIMessages.TargetProfileWindow_vm, info
260: .getVMArguments());
261: entry.getText().setLayoutData(new GridData(GridData.FILL_BOTH));
262:
263: toolkit.paintBordersFor(form.getBody());
264: return form;
265: }
266:
267: private FormEntry createEntry(Composite client,
268: FormToolkit toolkit, String text, String value) {
269: return createEntry(client, toolkit, text, value, SWT.NONE);
270: }
271:
272: private FormEntry createEntry(Composite client,
273: FormToolkit toolkit, String text, String value, int style) {
274: FormEntry entry = new FormEntry(client, toolkit, text, style);
275: entry.setValue(value);
276: entry.setEditable(false);
277: return entry;
278: }
279:
280: private String getLocation(ITarget target) {
281: ILocationInfo info = target.getLocationInfo();
282: if (info == null || info.useDefault())
283: return TargetPlatform.getDefaultLocation();
284: try {
285: return VariablesPlugin.getDefault()
286: .getStringVariableManager()
287: .performStringSubstitution(info.getPath());
288: } catch (CoreException e) {
289: }
290: return ""; //$NON-NLS-1$
291: }
292:
293: public boolean close() {
294: fToolkit.dispose();
295: return super.close();
296: }
297:
298: }
|