001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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: * Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog
011: * font should be activated and used by other components.
012: *******************************************************************************/package org.eclipse.ui.dialogs;
013:
014: import java.util.ArrayList;
015:
016: import org.eclipse.core.resources.IProject;
017: import org.eclipse.jface.resource.JFaceColors;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.layout.GridData;
020: import org.eclipse.swt.layout.GridLayout;
021: import org.eclipse.swt.widgets.Composite;
022: import org.eclipse.swt.widgets.Control;
023: import org.eclipse.swt.widgets.Label;
024: import org.eclipse.swt.widgets.Shell;
025: import org.eclipse.ui.PlatformUI;
026: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
027: import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
028: import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea;
029: import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter;
030:
031: /**
032: * The ProjectLocationMoveDialog is the dialog used to select the location of a
033: * project for moving.
034: */
035: public class ProjectLocationMoveDialog extends SelectionDialog {
036: private IProject project;
037:
038: private Label statusMessageLabel;
039:
040: private static String PROJECT_LOCATION_SELECTION_TITLE = IDEWorkbenchMessages.ProjectLocationSelectionDialog_selectionTitle;
041:
042: private ProjectContentsLocationArea locationArea;
043:
044: /**
045: * Create a ProjectLocationMoveDialog on the supplied project parented by
046: * the parentShell.
047: *
048: * @param parentShell
049: * @param existingProject
050: */
051: public ProjectLocationMoveDialog(Shell parentShell,
052: IProject existingProject) {
053: super (parentShell);
054: setTitle(PROJECT_LOCATION_SELECTION_TITLE);
055: this .project = existingProject;
056: }
057:
058: /*
059: * (non-Javadoc)
060: *
061: * @see org.eclipse.ui.dialogs.SelectionDialog#setMessage(java.lang.String)
062: */
063: public void setMessage(String message) {
064: super .setMessage(message);
065: if (statusMessageLabel != null) {
066: if (message == null) {
067: statusMessageLabel.setText("");//$NON-NLS-1$
068: statusMessageLabel.setToolTipText("");//$NON-NLS-1$
069: getOkButton().setEnabled(true);
070: } else {
071: statusMessageLabel.setForeground(JFaceColors
072: .getErrorText(statusMessageLabel.getDisplay()));
073: statusMessageLabel.setText(message);
074: statusMessageLabel.setToolTipText(message);
075: getOkButton().setEnabled(false);
076: }
077: }
078: }
079:
080: /*
081: * (non-Javadoc) Method declared in Window.
082: */
083: protected void configureShell(Shell shell) {
084: super .configureShell(shell);
085: PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
086: IIDEHelpContextIds.PROJECT_LOCATION_SELECTION_DIALOG);
087: }
088:
089: /*
090: * (non-Javadoc) Method declared on Dialog.
091: */
092: protected Control createContents(Composite parent) {
093: Control content = super .createContents(parent);
094: getOkButton().setEnabled(false);
095: return content;
096: }
097:
098: /*
099: * (non-Javadoc) Method declared on Dialog.
100: */
101: protected Control createDialogArea(Composite parent) {
102: // page group
103: Composite composite = (Composite) super
104: .createDialogArea(parent);
105:
106: composite.setLayout(new GridLayout());
107: composite.setLayoutData(new GridData(GridData.FILL_BOTH));
108:
109: locationArea = new ProjectContentsLocationArea(
110: getErrorReporter(), composite, 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(
118: GridData.FILL_BOTH));
119: statusMessageLabel.setFont(parent.getFont());
120: // Make it two lines.
121: statusMessageLabel.setText(" \n "); //$NON-NLS-1$
122:
123: applyDialogFont(composite);
124: return composite;
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 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 list = new ArrayList();
158: list.add(getProject().getName());
159: list.add(locationArea.getProjectLocation());
160: setResult(list);
161: super.okPressed();
162: }
163:
164: }
|