001: /*******************************************************************************
002: * Copyright (c) 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.wizards.provisioner.update;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.core.runtime.Status;
014: import org.eclipse.jface.dialogs.Dialog;
015: import org.eclipse.jface.dialogs.StatusDialog;
016: import org.eclipse.pde.core.plugin.TargetPlatform;
017: import org.eclipse.pde.internal.ui.PDEPlugin;
018: import org.eclipse.pde.internal.ui.PDEUIMessages;
019: import org.eclipse.pde.internal.ui.util.SWTUtil;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.events.ModifyEvent;
022: import org.eclipse.swt.events.ModifyListener;
023: import org.eclipse.swt.events.SelectionAdapter;
024: import org.eclipse.swt.events.SelectionEvent;
025: import org.eclipse.swt.layout.GridData;
026: import org.eclipse.swt.layout.GridLayout;
027: import org.eclipse.swt.widgets.Button;
028: import org.eclipse.swt.widgets.Composite;
029: import org.eclipse.swt.widgets.Control;
030: import org.eclipse.swt.widgets.DirectoryDialog;
031: import org.eclipse.swt.widgets.Label;
032: import org.eclipse.swt.widgets.Shell;
033: import org.eclipse.swt.widgets.Text;
034:
035: public class UpdateSiteProvisionerDialog extends StatusDialog {
036:
037: private Text fInstallLocationText;
038: private Label fInstallLocationLabel;
039: private Text fSiteLocationText;
040: private Label fSiteLocationLabel;
041: private IUpdateSiteProvisionerEntry fEntry;
042: private IStatus fOkStatus;
043: private IStatus fErrorStatus;
044:
045: private String fInstallLocation;
046: private String fSiteLocation;
047:
048: public UpdateSiteProvisionerDialog(Shell parent,
049: String installLocation, String siteLocation, String title) {
050: super (parent);
051: setShellStyle(getShellStyle() | SWT.RESIZE);
052: fInstallLocation = installLocation;
053: fSiteLocation = siteLocation;
054: setTitle(title);
055: }
056:
057: protected Control createDialogArea(Composite parent) {
058: Composite container = new Composite(parent, SWT.RESIZE);
059: GridLayout layout = new GridLayout();
060: layout.numColumns = 3;
061: layout.marginHeight = layout.marginWidth = 10;
062: container.setLayout(layout);
063: container.setLayoutData(new GridData(GridData.FILL_BOTH));
064:
065: createEntry(container);
066:
067: // add modify listeners
068: ModifyListener listener = new ModifyListener() {
069: public void modifyText(ModifyEvent e) {
070: dialogChanged();
071: }
072: };
073: fInstallLocationText.addModifyListener(listener);
074: fSiteLocationText.addModifyListener(listener);
075: Dialog.applyDialogFont(container);
076:
077: dialogChanged();
078:
079: return container;
080: }
081:
082: protected void createEntry(Composite container) {
083: fSiteLocationLabel = new Label(container, SWT.NONE);
084: fSiteLocationLabel
085: .setText(PDEUIMessages.UpdateSiteProvisionerDialog_siteLocation);
086:
087: fSiteLocationText = new Text(container, SWT.SINGLE | SWT.BORDER);
088: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
089: gd.horizontalSpan = 2;
090: fSiteLocationText.setLayoutData(gd);
091: if (fSiteLocation != null)
092: fSiteLocationText.setText(fSiteLocation);
093:
094: fInstallLocationLabel = new Label(container, SWT.NULL);
095: fInstallLocationLabel
096: .setText(PDEUIMessages.UpdateSiteProvisionerDialog_installLocation);
097:
098: fInstallLocationText = new Text(container, SWT.SINGLE
099: | SWT.BORDER);
100: gd = new GridData(GridData.FILL_HORIZONTAL);
101: gd.widthHint = 250;
102: fInstallLocationText.setLayoutData(gd);
103: if (fInstallLocation != null)
104: fInstallLocationText.setText(fInstallLocation);
105:
106: Button fs = new Button(container, SWT.PUSH);
107: fs
108: .setText(PDEUIMessages.UpdateSiteProvisionerDialog_fileSystem);
109: fs.setLayoutData(new GridData());
110: fs.addSelectionListener(new SelectionAdapter() {
111: public void widgetSelected(SelectionEvent e) {
112: handleBrowseFileSystem();
113: }
114: });
115: SWTUtil.setButtonDimensionHint(fs);
116: }
117:
118: private IStatus createErrorStatus(String message) {
119: return new Status(IStatus.ERROR, PDEPlugin.getPluginId(),
120: IStatus.OK, message, null);
121: }
122:
123: private void dialogChanged() {
124: IStatus status = null;
125: if (fInstallLocationText.getText().length() == 0
126: && fSiteLocationText.getText().length() == 0)
127: status = getEmptyErrorStatus();
128:
129: if (status == null)
130: status = getOKStatus();
131: updateStatus(status);
132: }
133:
134: private IStatus getOKStatus() {
135: if (fOkStatus == null)
136: fOkStatus = new Status(IStatus.OK, PDEPlugin.getPluginId(),
137: IStatus.OK, "", //$NON-NLS-1$
138: null);
139: return fOkStatus;
140: }
141:
142: private IStatus getEmptyErrorStatus() {
143: if (fErrorStatus == null)
144: fErrorStatus = createErrorStatus(PDEUIMessages.UpdateSiteProvisionerDialog_missBothErrorMessage);
145: return fErrorStatus;
146: }
147:
148: protected void handleBrowseFileSystem() {
149: DirectoryDialog dialog = new DirectoryDialog(getShell());
150:
151: String text = fInstallLocationText.getText();
152: if (text == null || text.length() == 0) {
153: dialog.setFilterPath(TargetPlatform.getLocation());
154: } else {
155: dialog.setFilterPath(fInstallLocationText.getText());
156: }
157: dialog.setText(PDEUIMessages.BaseBlock_dirSelection);
158: dialog.setMessage(PDEUIMessages.BaseBlock_dirChoose);
159: String result = dialog.open();
160: if (result != null) {
161: fInstallLocationText.setText(result);
162: }
163: }
164:
165: protected void okPressed() {
166: fEntry = new UpdateSiteProvisionerEntry(fInstallLocationText
167: .getText(), fSiteLocationText.getText());
168: super .okPressed();
169: }
170:
171: public IUpdateSiteProvisionerEntry getEntry() {
172: return fEntry;
173: }
174:
175: }
|