KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > reorg > RenameTypeWizardSimilarElementsOptionsDialog


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  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.refactoring.reorg;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Shell;
21
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.dialogs.IDialogConstants;
24 import org.eclipse.jface.dialogs.MessageDialog;
25
26 import org.eclipse.jdt.internal.corext.refactoring.rename.RenamingNameSuggestor;
27
28 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
29 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
30 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
31 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
32 import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
33
34 /**
35  * Option dialog for selecting a similarly named element renaming strategy
36  *
37  * @since 3.2
38  *
39  */

40 public class RenameTypeWizardSimilarElementsOptionsDialog extends MessageDialog {
41
42     private SelectionButtonDialogField fExactStrategyRadio;
43     private SelectionButtonDialogField fEmbeddedStrategyRadio;
44     private SelectionButtonDialogField fSuffixStrategyRadio;
45
46     private Label fWarningLabel;
47     private Label fWarningImageLabel;
48     private int fSelectedStrategy;
49
50     public RenameTypeWizardSimilarElementsOptionsDialog(Shell parentShell, int defaultStrategy) {
51         super(parentShell, RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_title, null, new String JavaDoc(), INFORMATION, new String JavaDoc[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
52         setShellStyle(getShellStyle() | SWT.RESIZE);
53         fSelectedStrategy= defaultStrategy;
54     }
55
56     /*
57      * (non-Javadoc)
58      *
59      * @see org.eclipse.jface.dialogs.IconAndMessageDialog#createMessageArea(org.eclipse.swt.widgets.Composite)
60      */

61     protected Control createMessageArea(Composite parent) {
62         initializeDialogUnits(parent);
63
64         Composite messageComposite= new Composite(parent, SWT.NONE);
65         messageComposite.setFont(parent.getFont());
66         GridLayout layout= new GridLayout();
67         layout.numColumns= 1;
68         layout.marginHeight= 0;
69         layout.marginWidth= 0;
70         layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
71         layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
72         messageComposite.setLayout(layout);
73         messageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
74
75         Label infoLabel= new Label(messageComposite, SWT.WRAP);
76         infoLabel.setText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_select_strategy);
77         GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false);
78         gd.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
79         infoLabel.setLayoutData(gd);
80         infoLabel.setFont(parent.getFont());
81
82         int indent= convertWidthInCharsToPixels(3);
83
84         fExactStrategyRadio= new SelectionButtonDialogField(SWT.RADIO);
85         fExactStrategyRadio.setLabelText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_strategy_1);
86         fExactStrategyRadio.doFillIntoGrid(messageComposite, 1);
87         fExactStrategyRadio.setSelection(fSelectedStrategy == RenamingNameSuggestor.STRATEGY_EXACT);
88         LayoutUtil.setHorizontalIndent(fExactStrategyRadio.getSelectionButton(null), indent);
89
90         fEmbeddedStrategyRadio= new SelectionButtonDialogField(SWT.RADIO);
91         fEmbeddedStrategyRadio.setLabelText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_strategy_2);
92         fEmbeddedStrategyRadio.doFillIntoGrid(messageComposite, 1);
93         fEmbeddedStrategyRadio.setSelection(fSelectedStrategy == RenamingNameSuggestor.STRATEGY_EMBEDDED);
94         LayoutUtil.setHorizontalIndent(fEmbeddedStrategyRadio.getSelectionButton(null), indent);
95
96         fSuffixStrategyRadio= new SelectionButtonDialogField(SWT.RADIO);
97         fSuffixStrategyRadio.setLabelText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_strategy_3);
98         fSuffixStrategyRadio.doFillIntoGrid(messageComposite, 1);
99         fSuffixStrategyRadio.setSelection(fSelectedStrategy == RenamingNameSuggestor.STRATEGY_SUFFIX);
100         LayoutUtil.setHorizontalIndent(fSuffixStrategyRadio.getSelectionButton(null), indent);
101
102         final Composite warningComposite= new Composite(messageComposite, SWT.NONE);
103         layout= new GridLayout();
104         layout.numColumns= 2;
105         layout.marginWidth= 0;
106         layout.marginHeight= 0;
107         warningComposite.setLayout(layout);
108         warningComposite.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
109         warningComposite.setFont(messageComposite.getFont());
110
111         Image image= Dialog.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
112         fWarningImageLabel= new Label(warningComposite, SWT.LEFT | SWT.WRAP);
113         fWarningImageLabel.setImage(image);
114         fWarningImageLabel.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 1, 1));
115
116         fWarningLabel= new Label(warningComposite, SWT.WRAP);
117         fWarningLabel.setText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_warning_short_names);
118         GridData gridData= new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1);
119         gridData.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
120         fWarningLabel.setLayoutData(gridData);
121         fWarningLabel.setFont(warningComposite.getFont());
122
123         fExactStrategyRadio.setDialogFieldListener(new IDialogFieldListener() {
124
125             public void dialogFieldChanged(DialogField field) {
126                 updateLabel();
127                 fSelectedStrategy= RenamingNameSuggestor.STRATEGY_EXACT;
128             }
129         });
130
131         fEmbeddedStrategyRadio.setDialogFieldListener(new IDialogFieldListener() {
132
133             public void dialogFieldChanged(DialogField field) {
134                 updateLabel();
135                 fSelectedStrategy= RenamingNameSuggestor.STRATEGY_EMBEDDED;
136             }
137         });
138
139         fSuffixStrategyRadio.setDialogFieldListener(new IDialogFieldListener() {
140
141             public void dialogFieldChanged(DialogField field) {
142                 updateLabel();
143                 fSelectedStrategy= RenamingNameSuggestor.STRATEGY_SUFFIX;
144             }
145         });
146
147         updateLabel();
148
149         return messageComposite;
150     }
151     
152     
153     protected boolean customShouldTakeFocus() {
154         return true;
155     }
156
157     private void updateLabel() {
158         fWarningImageLabel.setEnabled(!fExactStrategyRadio.isSelected());
159         fWarningLabel.setEnabled(!fExactStrategyRadio.isSelected());
160     }
161
162     /**
163      * @return one of the STRATEGY_* constants in {@link RenamingNameSuggestor}
164      */

165     public int getSelectedStrategy() {
166         return fSelectedStrategy;
167     }
168 }
169
Popular Tags