001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 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.wizards.exports;
011:
012: import org.eclipse.jface.dialogs.Dialog;
013: import org.eclipse.jface.dialogs.IDialogSettings;
014: import org.eclipse.pde.internal.ui.PDEUIMessages;
015: import org.eclipse.swt.SWT;
016: import org.eclipse.swt.events.ModifyEvent;
017: import org.eclipse.swt.events.ModifyListener;
018: import org.eclipse.swt.events.SelectionAdapter;
019: import org.eclipse.swt.events.SelectionEvent;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.layout.GridLayout;
022: import org.eclipse.swt.widgets.Button;
023: import org.eclipse.swt.widgets.Composite;
024: import org.eclipse.swt.widgets.Control;
025: import org.eclipse.swt.widgets.Label;
026: import org.eclipse.swt.widgets.Text;
027:
028: public class JNLPTab {
029:
030: private static final String S_JNLP = "jnlp"; //$NON-NLS-1$
031: private static final String S_URL = "siteURL"; //$NON-NLS-1$
032: private static final String S_JRE = "jre"; //$NON-NLS-1$
033:
034: private Label fURLLabel;
035: private Text fURLText;
036: private Label fVersionLabel;
037: private Text fVersionText;
038: private Button fButton;
039:
040: private BaseExportWizardPage fPage;
041:
042: public JNLPTab(BaseExportWizardPage page) {
043: fPage = page;
044: }
045:
046: public Control createControl(Composite parent) {
047: Composite jnlpGroup = new Composite(parent, SWT.NONE);
048: jnlpGroup.setLayout(new GridLayout(2, false));
049: jnlpGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
050:
051: fButton = new Button(jnlpGroup, SWT.CHECK);
052: fButton
053: .setText(PDEUIMessages.AdvancedFeatureExportPage_createJNLP);
054: GridData gd = new GridData();
055: gd.horizontalSpan = 2;
056: fButton.setLayoutData(gd);
057: fButton.addSelectionListener(new SelectionAdapter() {
058: public void widgetSelected(SelectionEvent e) {
059: updateGroup(fButton.getSelection());
060: fPage.pageChanged();
061: }
062: });
063:
064: fURLLabel = createLabel(jnlpGroup,
065: PDEUIMessages.AdvancedFeatureExportPage_siteURL);
066: fURLText = createText(jnlpGroup);
067:
068: fVersionLabel = createLabel(jnlpGroup,
069: PDEUIMessages.AdvancedFeatureExportPage_jreVersion);
070: fVersionText = createText(jnlpGroup);
071:
072: Dialog.applyDialogFont(jnlpGroup);
073: return jnlpGroup;
074: }
075:
076: protected Label createLabel(Composite parent, String text) {
077: Label label = new Label(parent, SWT.NONE);
078: label.setText(text);
079: GridData gd = new GridData();
080: gd.horizontalIndent = 15;
081: label.setLayoutData(gd);
082: return label;
083: }
084:
085: protected Text createText(Composite parent) {
086: Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
087: text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
088: text.addModifyListener(new ModifyListener() {
089: public void modifyText(ModifyEvent e) {
090: fPage.pageChanged();
091: }
092: });
093: return text;
094: }
095:
096: protected void initialize(IDialogSettings settings) {
097: fURLText.setText(getString(settings, S_URL));
098: fVersionText.setText(getString(settings, S_JRE));
099: fButton.setSelection(settings.getBoolean(S_JNLP));
100: updateGroup(fButton.getSelection());
101: }
102:
103: private String getString(IDialogSettings settings, String key) {
104: String value = settings.get(key);
105: return value == null ? "" : value; //$NON-NLS-1$
106: }
107:
108: private void updateGroup(boolean enabled) {
109: fURLLabel.setEnabled(enabled);
110: fURLText.setEnabled(enabled);
111: fVersionLabel.setEnabled(enabled);
112: fVersionText.setEnabled(enabled);
113: }
114:
115: protected String validate() {
116: String error = null;
117: if (fButton.getSelection()) {
118: if (fURLText.getText().trim().length() == 0) {
119: error = PDEUIMessages.AdvancedFeatureExportPage_noSite;
120: } else if (fVersionText.getText().trim().length() == 0) {
121: error = PDEUIMessages.AdvancedFeatureExportPage_noVersion;
122: }
123: }
124: return error;
125: }
126:
127: protected void saveSettings(IDialogSettings settings) {
128: settings.put(S_JNLP, fButton.getSelection());
129: settings.put(S_URL, fURLText.getText());
130: settings.put(S_JRE, fVersionText.getText());
131: }
132:
133: protected String[] getJNLPInfo() {
134: if (fButton.getSelection()) {
135: return new String[] { fURLText.getText().trim(),
136: fVersionText.getText().trim() };
137: }
138: return null;
139: }
140: }
|