KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > history > EditRefactoringDetailsDialog


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.ltk.internal.ui.refactoring.history;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.swt.widgets.Text;
20
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.dialogs.IDialogConstants;
23
24 /**
25  * Dialog to edit the details of a refactoring.
26  *
27  * @since 3.2
28  */

29 public final class EditRefactoringDetailsDialog extends Dialog {
30
31     /** The detail text */
32     private String JavaDoc fDetails= "";//$NON-NLS-1$
33

34     /** The details text field */
35     private Text fDetailsField;
36
37     /** The message to display */
38     private final String JavaDoc fMessage;
39
40     /** The dialog title */
41     private final String JavaDoc fTitle;
42
43     /**
44      * Creates a new edit details dialog.
45      *
46      * @param shell
47      * the parent shell, or <code>null</code>
48      * @param title
49      * the dialog title, or <code>null</code> if none
50      * @param message
51      * the dialog message, or <code>null</code> if none
52      * @param details
53      * the initial details, or <code>null</code> if none
54      */

55     public EditRefactoringDetailsDialog(final Shell shell, final String JavaDoc title, final String JavaDoc message, final String JavaDoc details) {
56         super(shell);
57         fTitle= title;
58         fMessage= message;
59         if (details == null)
60             fDetails= "";//$NON-NLS-1$
61
else
62             fDetails= details;
63     }
64
65     /**
66      * {@inheritDoc}
67      */

68     protected void buttonPressed(final int id) {
69         if (id == IDialogConstants.OK_ID)
70             fDetails= fDetailsField.getText();
71         else
72             fDetails= null;
73         super.buttonPressed(id);
74     }
75
76     /**
77      * {@inheritDoc}
78      */

79     protected void configureShell(final Shell shell) {
80         super.configureShell(shell);
81         if (fTitle != null)
82             shell.setText(fTitle);
83     }
84
85     /**
86      * {@inheritDoc}
87      */

88     protected void createButtonsForButtonBar(final Composite parent) {
89         createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
90         createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
91         fDetailsField.setFocus();
92         if (fDetails != null) {
93             fDetailsField.setText(fDetails);
94             fDetailsField.selectAll();
95         }
96     }
97
98     /**
99      * {@inheritDoc}
100      */

101     protected Control createDialogArea(final Composite parent) {
102         initializeDialogUnits(parent);
103         final Composite composite= (Composite) super.createDialogArea(parent);
104         if (fMessage != null) {
105             final Label label= new Label(composite, SWT.WRAP);
106             label.setText(fMessage);
107             final GridData data= new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
108             data.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
109             label.setLayoutData(data);
110             label.setFont(parent.getFont());
111         }
112         fDetailsField= new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
113         final GridData data= new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
114         data.heightHint= convertHeightInCharsToPixels(8);
115         fDetailsField.setLayoutData(data);
116         applyDialogFont(composite);
117         return composite;
118     }
119
120     /**
121      * Returns the current details.
122      *
123      * @return the current details
124      */

125     public String JavaDoc getDetails() {
126         return fDetails;
127     }
128 }
129
Popular Tags