]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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.layout.GridData; | |
15 | import org.eclipse.swt.layout.GridLayout; | |
16 | import org.eclipse.swt.widgets.Composite; | |
17 | import org.eclipse.swt.widgets.Control; | |
18 | import org.eclipse.swt.widgets.Label; | |
19 | import org.eclipse.swt.widgets.Shell; | |
20 | ||
21 | import org.eclipse.jface.dialogs.IDialogConstants; | |
22 | import org.eclipse.jface.dialogs.MessageDialog; | |
23 | ||
24 | import org.eclipse.jdt.internal.corext.refactoring.rename.RenamingNameSuggestor; | |
25 | ||
26 | import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; | |
27 | import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; | |
28 | import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; | |
29 | import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; | |
30 | import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; | |
31 | ||
32 | /** | |
33 | * Option dialog for selecting a similarly named element renaming strategy | |
34 | * | |
35 | * @since 3.2 | |
36 | * | |
37 | */ | |
38 | public class RenameTypeWizardSimilarElementsOptionsDialog extends MessageDialog { | |
39 | ||
40 | public SelectionButtonDialogField fExactStrategyRadio; | |
41 | private SelectionButtonDialogField fEmbeddedStrategyRadio; | |
42 | public SelectionButtonDialogField fSuffixStrategyRadio; | |
43 | ||
44 | public Label fWarningLabel; | |
45 | public Label fWarningImageLabel; | |
46 | public int fSelectedStrategy; | |
47 | ||
48 | public RenameTypeWizardSimilarElementsOptionsDialog(Shell parentShell, int defaultStrategy) { | |
49 | super(parentShell, RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_title, null, new String(), INFORMATION, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); | |
50 | fSelectedStrategy= defaultStrategy; | |
51 | } | |
52 | ||
53 | /* | |
54 | * @see org.eclipse.jface.dialogs.Dialog#isResizable() | |
55 | * @since 3.4 | |
56 | */ | |
57 | @Override | |
58 | protected boolean isResizable() { | |
59 | return true; | |
60 | } | |
61 | ||
62 | /* | |
63 | * (non-Javadoc) | |
64 | * | |
65 | * @see org.eclipse.jface.dialogs.IconAndMessageDialog#createMessageArea(org.eclipse.swt.widgets.Composite) | |
66 | */ | |
67 | @Override | |
68 | protected Control createMessageArea(Composite parent) { | |
69 | initializeDialogUnits(parent); | |
70 | ||
71 | Composite messageComposite= new Composite(parent, SWT.NONE); | |
72 | messageComposite.setFont(parent.getFont()); | |
73 | GridLayout layout= new GridLayout(); | |
74 | layout.numColumns= 1; | |
75 | layout.marginHeight= 0; | |
76 | layout.marginWidth= 0; | |
77 | layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); | |
78 | layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); | |
79 | messageComposite.setLayout(layout); | |
80 | messageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
81 | ||
82 | Label infoLabel= new Label(messageComposite, SWT.WRAP); | |
83 | infoLabel.setText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_select_strategy); | |
84 | GridData gd= new GridData(GridData.FILL, GridData.CENTER, true, false); | |
85 | gd.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); | |
86 | infoLabel.setLayoutData(gd); | |
87 | infoLabel.setFont(parent.getFont()); | |
88 | ||
89 | int indent= convertWidthInCharsToPixels(3); | |
90 | ||
91 | fExactStrategyRadio= new SelectionButtonDialogField(SWT.RADIO); | |
92 | fExactStrategyRadio.setLabelText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_strategy_1); | |
93 | fExactStrategyRadio.doFillIntoGrid(messageComposite, 1); | |
94 | fExactStrategyRadio.setSelection(fSelectedStrategy == RenamingNameSuggestor.STRATEGY_EXACT); | |
95 | LayoutUtil.setHorizontalIndent(fExactStrategyRadio.getSelectionButton(null), indent); | |
96 | ||
97 | fEmbeddedStrategyRadio= new SelectionButtonDialogField(SWT.RADIO); | |
98 | fEmbeddedStrategyRadio.setLabelText(RefactoringMessages.RenameTypeWizardSimilarElementsOptionsDialog_strategy_2); | |
99 | fEmbeddedStrategyRadio.doFillIntoGrid(messageComposite, 1); | |
100 | fEmbeddedStrategyRadio.setSelection(fSelectedStrategy == RenamingNameSuggestor.STRATEGY_EMBEDDED); | |
101 | LayoutUtil.setHorizontalIndent(fEmbeddedStrategyRadio.getSelectionButton(null), indent); | |
102 | ||
103 | fSuffixStrategyRadio= new SelectionButtonDialogField(SWT.RADIO); | |
104 | final Composite warningComposite= fSuffixStrategyRadio.generated_4513097341604212477(this, messageComposite, indent); | |
105 | GridData gridData= new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1); | |
106 | gridData.widthHint= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); | |
107 | fWarningLabel.setLayoutData(gridData); | |
108 | fWarningLabel.setFont(warningComposite.getFont()); | |
109 | ||
110 | fExactStrategyRadio.setDialogFieldListener(new IDialogFieldListener() { | |
111 | ||
112 | public void dialogFieldChanged(DialogField field) { | |
113 | updateLabel(); | |
114 | fSelectedStrategy= RenamingNameSuggestor.STRATEGY_EXACT; | |
115 | } | |
116 | }); | |
117 | ||
118 | fEmbeddedStrategyRadio.setDialogFieldListener(new IDialogFieldListener() { | |
119 | ||
120 | public void dialogFieldChanged(DialogField field) { | |
121 | updateLabel(); | |
122 | fSelectedStrategy= RenamingNameSuggestor.STRATEGY_EMBEDDED; | |
123 | } | |
124 | }); | |
125 | ||
126 | fSuffixStrategyRadio.setDialogFieldListener(new IDialogFieldListener() { | |
127 | ||
128 | public void dialogFieldChanged(DialogField field) { | |
129 | updateLabel(); | |
130 | fSelectedStrategy= RenamingNameSuggestor.STRATEGY_SUFFIX; | |
131 | } | |
132 | }); | |
133 | ||
134 | updateLabel(); | |
135 | ||
136 | return messageComposite; | |
137 | } | |
138 | ||
139 | @Override | |
140 | protected boolean customShouldTakeFocus() { | |
141 | return true; | |
142 | } | |
143 | ||
144 | private void updateLabel() { | |
145 | fExactStrategyRadio.generated_1746865616878513464(this); | |
146 | } | |
147 | ||
148 | /** | |
149 | * @return one of the STRATEGY_* constants in {@link RenamingNameSuggestor} | |
150 | */ | |
151 | public int getSelectedStrategy() { | |
152 | return fSelectedStrategy; | |
153 | } | |
154 | } |