KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > jres > VMDetailsDialog


1 /*******************************************************************************
2  * Copyright (c) 2006 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.jdt.internal.debug.ui.jres;
12
13
14 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds;
15 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
16 import org.eclipse.jdt.launching.IVMInstall;
17 import org.eclipse.jdt.launching.IVMInstall2;
18 import org.eclipse.jdt.launching.JavaRuntime;
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.dialogs.IDialogConstants;
21 import org.eclipse.jface.dialogs.IDialogSettings;
22 import org.eclipse.jface.viewers.TreeViewer;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.ui.PlatformUI;
31
32 /**
33  * Displays details of a VM install (read only, for contributed VMs).
34  *
35  * @since 3.2
36  */

37 public class VMDetailsDialog extends Dialog {
38     
39     private IVMInstall fVM;
40         
41     public VMDetailsDialog(Shell shell, IVMInstall vm) {
42         super(shell);
43         setShellStyle(getShellStyle() | SWT.RESIZE);
44         fVM= vm;
45     }
46     
47     /**
48      * @see Windows#configureShell
49      */

50     protected void configureShell(Shell newShell) {
51         super.configureShell(newShell);
52         newShell.setText(JREMessages.VMDetailsDialog_0);
53         PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaDebugHelpContextIds.JRE_DETAILS_DIALOG);
54     }
55             
56     protected Control createDialogArea(Composite ancestor) {
57         Composite parent = (Composite)super.createDialogArea(ancestor);
58         GridLayout layout = new GridLayout(2, false);
59         parent.setLayout(layout);
60         
61         // type
62
createLabel(parent, JREMessages.addVMDialog_jreType);
63         createLabel(parent, fVM.getVMInstallType().getName());
64
65         // name
66
createLabel(parent, JREMessages.addVMDialog_jreName);
67         createLabel(parent, fVM.getName());
68         
69         // home
70
createLabel(parent, JREMessages.addVMDialog_jreHome);
71         createLabel(parent, fVM.getInstallLocation().getAbsolutePath());
72         
73         // vm args
74
createLabel(parent, JREMessages.AddVMDialog_23);
75         String JavaDoc text = null;
76         if (fVM instanceof IVMInstall2) {
77             text = ((IVMInstall2)fVM).getVMArgs();
78         } else {
79             String JavaDoc[] args = fVM.getVMArguments();
80             if (args != null) {
81                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
82                 for (int i = 0; i < args.length; i++) {
83                     buf.append(args[i]);
84                     if (i < (args.length - 1)) {
85                         buf.append(" "); //$NON-NLS-1$
86
}
87                 }
88                 text = buf.toString();
89             }
90         }
91         if (text == null) {
92             text = ""; //$NON-NLS-1$
93
}
94         createLabel(parent, text);
95         
96         // libraries
97
Label label = createLabel(parent, JREMessages.AddVMDialog_JRE_system_libraries__1);
98         GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_BEGINNING);
99         label.setLayoutData(gd);
100         TreeViewer libraryViewer= new TreeViewer(parent);
101         gd = new GridData(GridData.FILL_BOTH);
102         gd.heightHint = 6;
103         libraryViewer.getControl().setLayoutData(gd);
104         LibraryContentProvider provider = new LibraryContentProvider();
105         libraryViewer.setContentProvider(provider);
106         libraryViewer.setLabelProvider(new LibraryLabelProvider());
107         libraryViewer.setInput(this);
108         provider.setLibraries(JavaRuntime.getLibraryLocations(fVM));
109         
110         applyDialogFont(parent);
111         return parent;
112     }
113     
114     private Label createLabel(Composite parent, String JavaDoc text) {
115         Label label = new Label(parent, SWT.NONE);
116         label.setText(text);
117         return label;
118     }
119     
120     /**
121      * Returns the name of the section that this dialog stores its settings in
122      *
123      * @return String
124      */

125     protected String JavaDoc getDialogSettingsSectionName() {
126         return "VM_DETAILS_DIALOG_SECTION"; //$NON-NLS-1$
127
}
128     
129      /* (non-Javadoc)
130      * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
131      */

132     protected IDialogSettings getDialogBoundsSettings() {
133          IDialogSettings settings = JDIDebugUIPlugin.getDefault().getDialogSettings();
134          IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
135          if (section == null) {
136              section = settings.addNewSection(getDialogSettingsSectionName());
137          }
138          return section;
139     }
140     
141     /* (non-Javadoc)
142      * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
143      */

144     protected void createButtonsForButtonBar(Composite parent) {
145         // create OK and Cancel buttons by default
146
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
147                 true);
148     }
149 }
150
Popular Tags