KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > dialogs > ProjectLocationMoveDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog
11  * font should be activated and used by other components.
12  *******************************************************************************/

13 package org.eclipse.ui.dialogs;
14
15 import java.util.ArrayList JavaDoc;
16
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.jface.resource.JFaceColors;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Shell;
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
28 import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
29 import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea;
30 import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter;
31
32 /**
33  * The ProjectLocationMoveDialog is the dialog used to select the location of a
34  * project for moving.
35  */

36 public class ProjectLocationMoveDialog extends SelectionDialog {
37     private IProject project;
38
39     private Label statusMessageLabel;
40
41     private static String JavaDoc PROJECT_LOCATION_SELECTION_TITLE = IDEWorkbenchMessages.ProjectLocationSelectionDialog_selectionTitle;
42
43
44     private ProjectContentsLocationArea locationArea;
45
46     /**
47      * Create a ProjectLocationMoveDialog on the supplied project parented by
48      * the parentShell.
49      *
50      * @param parentShell
51      * @param existingProject
52      */

53     public ProjectLocationMoveDialog(Shell parentShell, IProject existingProject) {
54         super(parentShell);
55         setTitle(PROJECT_LOCATION_SELECTION_TITLE);
56         this.project = existingProject;
57     }
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see org.eclipse.ui.dialogs.SelectionDialog#setMessage(java.lang.String)
63      */

64     public void setMessage(String JavaDoc message) {
65         super.setMessage(message);
66         if (statusMessageLabel != null) {
67             if (message == null) {
68                 statusMessageLabel.setText("");//$NON-NLS-1$
69
statusMessageLabel.setToolTipText("");//$NON-NLS-1$
70
getOkButton().setEnabled(true);
71             } else {
72                 statusMessageLabel.setForeground(JFaceColors
73                         .getErrorText(statusMessageLabel.getDisplay()));
74                 statusMessageLabel.setText(message);
75                 statusMessageLabel.setToolTipText(message);
76                 getOkButton().setEnabled(false);
77             }
78         }
79     }
80
81     /*
82      * (non-Javadoc) Method declared in Window.
83      */

84     protected void configureShell(Shell shell) {
85         super.configureShell(shell);
86         PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
87                 IIDEHelpContextIds.PROJECT_LOCATION_SELECTION_DIALOG);
88     }
89
90     /*
91      * (non-Javadoc) Method declared on Dialog.
92      */

93     protected Control createContents(Composite parent) {
94         Control content = super.createContents(parent);
95         getOkButton().setEnabled(false);
96         return content;
97     }
98
99     /*
100      * (non-Javadoc) Method declared on Dialog.
101      */

102     protected Control createDialogArea(Composite parent) {
103         // page group
104
Composite composite = (Composite) super.createDialogArea(parent);
105
106         composite.setLayout(new GridLayout());
107         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
108
109         locationArea = new ProjectContentsLocationArea(getErrorReporter(), composite,
110                 this.project);
111
112         // Scale the button based on the rest of the dialog
113
setButtonLayoutData(locationArea.getBrowseButton());
114
115         // Add in a label for status messages if required
116
statusMessageLabel = new Label(composite, SWT.WRAP);
117         statusMessageLabel.setLayoutData(new GridData(GridData.FILL_BOTH));
118         statusMessageLabel.setFont(parent.getFont());
119         // Make it two lines.
120
statusMessageLabel.setText(" \n "); //$NON-NLS-1$
121

122         applyDialogFont(composite);
123         return composite;
124     }
125
126
127     /**
128      * Get an error reporter for the receiver.
129      * @return IErrorMessageReporter
130      */

131     private IErrorMessageReporter getErrorReporter() {
132         return new IErrorMessageReporter(){
133             /* (non-Javadoc)
134              * @see org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter#reportError(java.lang.String)
135              */

136             public void reportError(String JavaDoc errorMessage) {
137                 setMessage(errorMessage);
138                 
139             }
140         };
141     }
142
143     /**
144      * Get the project being manipulated.
145      */

146     private IProject getProject() {
147         return this.project;
148     }
149
150     /**
151      * The <code>ProjectLocationMoveDialog</code> implementation of this
152      * <code>Dialog</code> method builds a two element list - the first
153      * element is the project name and the second one is the location.
154      */

155     protected void okPressed() {
156
157         ArrayList JavaDoc list = new ArrayList JavaDoc();
158         list.add(getProject().getName());
159         list.add(locationArea.getProjectLocation());
160         setResult(list);
161         super.okPressed();
162     }
163
164 }
165
Popular Tags