KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > JNLPTab


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.pde.internal.ui.wizards.exports;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.dialogs.IDialogSettings;
15 import org.eclipse.pde.internal.ui.PDEUIMessages;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.ModifyEvent;
18 import org.eclipse.swt.events.ModifyListener;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Text;
28
29 public class JNLPTab {
30     
31     private static final String JavaDoc S_JNLP = "jnlp"; //$NON-NLS-1$
32
private static final String JavaDoc S_URL = "siteURL"; //$NON-NLS-1$
33
private static final String JavaDoc S_JRE = "jre"; //$NON-NLS-1$
34

35     private Label fURLLabel;
36     private Text fURLText;
37     private Label fVersionLabel;
38     private Text fVersionText;
39     private Button fButton;
40     
41     private BaseExportWizardPage fPage;
42     
43     public JNLPTab(BaseExportWizardPage page) {
44         fPage = page;
45     }
46
47     public Control createControl(Composite parent) {
48         Composite jnlpGroup = new Composite(parent, SWT.NONE);
49         jnlpGroup.setLayout(new GridLayout(2, false));
50         jnlpGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
51         
52         fButton = new Button(jnlpGroup, SWT.CHECK);
53         fButton.setText(PDEUIMessages.AdvancedFeatureExportPage_createJNLP);
54         GridData gd = new GridData();
55         gd.horizontalSpan = 2;
56         fButton.setLayoutData(gd);
57         fButton.addSelectionListener(new SelectionAdapter() {
58             public void widgetSelected(SelectionEvent e) {
59                 updateGroup(fButton.getSelection());
60                 fPage.pageChanged();
61             }
62         });
63
64         fURLLabel = createLabel(jnlpGroup, PDEUIMessages.AdvancedFeatureExportPage_siteURL);
65         fURLText = createText(jnlpGroup);
66         
67         fVersionLabel = createLabel(jnlpGroup, PDEUIMessages.AdvancedFeatureExportPage_jreVersion);
68         fVersionText = createText(jnlpGroup);
69         
70         Dialog.applyDialogFont(jnlpGroup);
71         return jnlpGroup;
72     }
73     
74     protected Label createLabel(Composite parent, String JavaDoc text) {
75         Label label = new Label(parent, SWT.NONE);
76         label.setText(text);
77         GridData gd = new GridData();
78         gd.horizontalIndent = 15;
79         label.setLayoutData(gd);
80         return label;
81     }
82     
83     protected Text createText(Composite parent) {
84         Text text = new Text(parent, SWT.SINGLE|SWT.BORDER);
85         text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
86         text.addModifyListener(new ModifyListener() {
87             public void modifyText(ModifyEvent e) {
88                 fPage.pageChanged();
89             }
90         });
91         return text;
92     }
93     
94     protected void initialize(IDialogSettings settings) {
95         fURLText.setText(getString(settings, S_URL));
96         fVersionText.setText(getString(settings, S_JRE));
97         fButton.setSelection(settings.getBoolean(S_JNLP));
98         updateGroup(fButton.getSelection());
99     }
100     
101     private String JavaDoc getString(IDialogSettings settings, String JavaDoc key) {
102         String JavaDoc value = settings.get(key);
103         return value == null ? "" : value; //$NON-NLS-1$
104
}
105     
106     private void updateGroup(boolean enabled) {
107         fURLLabel.setEnabled(enabled);
108         fURLText.setEnabled(enabled);
109         fVersionLabel.setEnabled(enabled);
110         fVersionText.setEnabled(enabled);
111     }
112     
113     protected String JavaDoc validate() {
114         String JavaDoc error = null;
115         if (fButton.getSelection()) {
116             if (fURLText.getText().trim().length() == 0) {
117                 error = PDEUIMessages.AdvancedFeatureExportPage_noSite;
118             } else if (fVersionText.getText().trim().length() == 0) {
119                 error = PDEUIMessages.AdvancedFeatureExportPage_noVersion;
120             }
121         }
122         return error;
123     }
124     
125     protected void saveSettings(IDialogSettings settings) {
126         settings.put(S_JNLP, fButton.getSelection());
127         settings.put(S_URL, fURLText.getText());
128         settings.put(S_JRE, fVersionText.getText());
129     }
130     
131     protected String JavaDoc[] getJNLPInfo() {
132         if (fButton.getSelection()) {
133             return new String JavaDoc[] {
134                     fURLText.getText().trim(),
135                     fVersionText.getText().trim()};
136         }
137         return null;
138     }
139 }
140
Popular Tags