KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.debug.ui.jres;
12
13
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.jdt.core.IClasspathEntry;
17 import org.eclipse.jdt.core.JavaCore;
18 import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
19 import org.eclipse.jdt.launching.JavaRuntime;
20 import org.eclipse.jdt.ui.wizards.IClasspathContainerPage;
21 import org.eclipse.jface.util.IPropertyChangeListener;
22 import org.eclipse.jface.util.PropertyChangeEvent;
23 import org.eclipse.jface.wizard.WizardPage;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.graphics.Image;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Composite;
29
30 /**
31  * Extension to allow a user to associate a JRE with a Java project.
32  */

33 public class JREContainerWizardPage extends WizardPage implements IClasspathContainerPage {
34     
35     /**
36      * The classpath entry to be created.
37      */

38     private IClasspathEntry fSelection;
39     
40     /**
41      * JRE control
42      */

43     private JREsComboBlock fJREBlock;
44     
45     /**
46      * Constructs a new page.
47      */

48     public JREContainerWizardPage() {
49         super(JREMessages.JREContainerWizardPage_JRE_System_Library_1);
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#finish()
54      */

55     public boolean finish() {
56         IPath path = fJREBlock.getPath();
57         fSelection = JavaCore.newContainerEntry(path);
58         return true;
59     }
60
61     /* (non-Javadoc)
62      * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#getSelection()
63      */

64     public IClasspathEntry getSelection() {
65         return fSelection;
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#setSelection(org.eclipse.jdt.core.IClasspathEntry)
70      */

71     public void setSelection(IClasspathEntry containerEntry) {
72         fSelection = containerEntry;
73         initializeFromSelection();
74     }
75
76     /**
77      * Initlaizes the JRE selection
78      */

79     protected void initializeFromSelection() {
80         if (getControl() != null) {
81             if (fSelection == null) {
82                 fJREBlock.setPath(JavaRuntime.newDefaultJREContainerPath());
83             } else {
84                 fJREBlock.setPath(fSelection.getPath());
85                 IStatus status = fJREBlock.getStatus();
86                 if (!status.isOK()) {
87                     setErrorMessage(status.getMessage());
88                 }
89             }
90         }
91     }
92     
93     /* (non-Javadoc)
94      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
95      */

96     public void createControl(Composite parent) {
97         Composite composite = new Composite(parent, SWT.NONE);
98         GridLayout layout = new GridLayout();
99         composite.setLayout(layout);
100         GridData gd = new GridData(GridData.FILL_BOTH);
101         composite.setLayoutData(gd);
102         composite.setFont(parent.getFont());
103         fJREBlock = new JREsComboBlock();
104         fJREBlock.setDefaultJREDescriptor(new BuildJREDescriptor());
105         fJREBlock.setTitle(JREMessages.JREContainerWizardPage_3);
106         fJREBlock.createControl(composite);
107         gd = new GridData(GridData.FILL_HORIZONTAL);
108         fJREBlock.getControl().setLayoutData(gd);
109         setControl(composite);
110         fJREBlock.addPropertyChangeListener(new IPropertyChangeListener() {
111             public void propertyChange(PropertyChangeEvent event) {
112                 IStatus status = fJREBlock.getStatus();
113                 if (status.isOK()) {
114                     setErrorMessage(null);
115                 } else {
116                     setErrorMessage(status.getMessage());
117                 }
118             }
119         });
120         
121         setTitle(JREMessages.JREContainerWizardPage_JRE_System_Library_1);
122         setMessage(JREMessages.JREContainerWizardPage_Select_the_JRE_used_to_build_this_project__4);
123                 
124         initializeFromSelection();
125     }
126
127     /* (non-Javadoc)
128      * @see org.eclipse.jface.dialogs.IDialogPage#getImage()
129      */

130     public Image getImage() {
131         return JavaDebugImages.get(JavaDebugImages.IMG_WIZBAN_LIBRARY);
132     }
133
134 }
135
Popular Tags