KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > provisioner > update > UpdateSiteProvisionerDialog


1 /*******************************************************************************
2  * Copyright (c) 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.pde.internal.ui.wizards.provisioner.update;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.StatusDialog;
17 import org.eclipse.pde.core.plugin.TargetPlatform;
18 import org.eclipse.pde.internal.ui.PDEPlugin;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.pde.internal.ui.util.SWTUtil;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.ModifyEvent;
23 import org.eclipse.swt.events.ModifyListener;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.swt.widgets.DirectoryDialog;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Shell;
34 import org.eclipse.swt.widgets.Text;
35
36 public class UpdateSiteProvisionerDialog extends StatusDialog {
37
38     private Text fInstallLocationText;
39     private Label fInstallLocationLabel;
40     private Text fSiteLocationText;
41     private Label fSiteLocationLabel;
42     private IUpdateSiteProvisionerEntry fEntry;
43     private IStatus fOkStatus;
44     private IStatus fErrorStatus;
45
46     private String JavaDoc fInstallLocation;
47     private String JavaDoc fSiteLocation;
48
49     public UpdateSiteProvisionerDialog(Shell parent, String JavaDoc installLocation, String JavaDoc siteLocation, String JavaDoc title) {
50         super(parent);
51         fInstallLocation = installLocation;
52         fSiteLocation = siteLocation;
53         setTitle(title);
54     }
55
56     protected Control createDialogArea(Composite parent) {
57         Composite container = new Composite(parent, SWT.NULL);
58         GridLayout layout = new GridLayout();
59         layout.numColumns = 3;
60         layout.marginHeight = layout.marginWidth = 10;
61         container.setLayout(layout);
62         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
63         container.setLayoutData(gd);
64
65         createEntry(container);
66
67         // add modify listeners
68
ModifyListener listener = new ModifyListener() {
69             public void modifyText(ModifyEvent e) {
70                 dialogChanged();
71             }
72         };
73         fInstallLocationText.addModifyListener(listener);
74         fSiteLocationText.addModifyListener(listener);
75         Dialog.applyDialogFont(container);
76
77         dialogChanged();
78
79         return container;
80     }
81
82     protected void createEntry(Composite container) {
83         fSiteLocationLabel = new Label(container, SWT.NONE);
84         fSiteLocationLabel.setText(PDEUIMessages.UpdateSiteProvisionerDialog_siteLocation);
85
86         fSiteLocationText = new Text(container, SWT.SINGLE | SWT.BORDER);
87         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
88         gd.horizontalSpan = 2;
89         fSiteLocationText.setLayoutData(gd);
90         if(fSiteLocation != null)
91             fSiteLocationText.setText(fSiteLocation);
92
93         fInstallLocationLabel = new Label(container, SWT.NULL);
94         fInstallLocationLabel.setText(PDEUIMessages.UpdateSiteProvisionerDialog_installLocation);
95
96         fInstallLocationText = new Text(container, SWT.SINGLE | SWT.BORDER);
97         gd = new GridData(GridData.FILL_HORIZONTAL);
98         gd.widthHint = 250;
99         fInstallLocationText.setLayoutData(gd);
100         if(fInstallLocation != null)
101             fInstallLocationText.setText(fInstallLocation);
102
103         Button fs = new Button(container, SWT.PUSH);
104         fs.setText(PDEUIMessages.UpdateSiteProvisionerDialog_fileSystem);
105         fs.setLayoutData(new GridData());
106         fs.addSelectionListener(new SelectionAdapter() {
107             public void widgetSelected(SelectionEvent e) {
108                 handleBrowseFileSystem();
109             }
110         });
111         SWTUtil.setButtonDimensionHint(fs);
112     }
113
114     private IStatus createErrorStatus(String JavaDoc message) {
115         return new Status(IStatus.ERROR, PDEPlugin.getPluginId(), IStatus.OK,
116                 message, null);
117     }
118
119     private void dialogChanged() {
120         IStatus status = null;
121         if(fInstallLocationText.getText().length() == 0 && fSiteLocationText.getText().length() == 0)
122             status = getEmptyErrorStatus();
123
124         if (status == null)
125             status = getOKStatus();
126         updateStatus(status);
127     }
128
129     private IStatus getOKStatus() {
130         if (fOkStatus == null)
131             fOkStatus = new Status(IStatus.OK, PDEPlugin.getPluginId(),
132                     IStatus.OK, "", //$NON-NLS-1$
133
null);
134         return fOkStatus;
135     }
136
137     private IStatus getEmptyErrorStatus() {
138         if (fErrorStatus == null)
139             fErrorStatus = createErrorStatus(PDEUIMessages.UpdateSiteProvisionerDialog_missBothErrorMessage);
140         return fErrorStatus;
141     }
142
143     protected void handleBrowseFileSystem() {
144         DirectoryDialog dialog = new DirectoryDialog(getShell());
145
146         String JavaDoc text = fInstallLocationText.getText();
147         if(text == null || text.length() == 0) {
148             dialog.setFilterPath(TargetPlatform.getLocation());
149         } else {
150             dialog.setFilterPath(fInstallLocationText.getText());
151         }
152         dialog.setText(PDEUIMessages.BaseBlock_dirSelection);
153         dialog.setMessage(PDEUIMessages.BaseBlock_dirChoose);
154         String JavaDoc result = dialog.open();
155         if (result != null) {
156             fInstallLocationText.setText(result);
157         }
158     }
159
160     protected void okPressed() {
161         fEntry = new UpdateSiteProvisionerEntry(
162                 fInstallLocationText.getText(),
163                 fSiteLocationText.getText());
164         super.okPressed();
165     }
166
167     public IUpdateSiteProvisionerEntry getEntry() {
168         return fEntry;
169     }
170
171 }
172
Popular Tags