mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 06:11:42 +07:00
introduce parameter object: ui clarification; visibility can be fixed for writable files only
This commit is contained in:
+9
-9
@@ -32,11 +32,11 @@ import com.intellij.refactoring.RefactorJBundle;
|
||||
import com.intellij.refactoring.RefactoringBundle;
|
||||
import com.intellij.refactoring.ui.PackageNameReferenceEditorCombo;
|
||||
import com.intellij.refactoring.ui.RefactoringDialog;
|
||||
import com.intellij.refactoring.ui.VisibilityPanel;
|
||||
import com.intellij.refactoring.util.ParameterTablePanel;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.RecentsManager;
|
||||
import com.intellij.ui.ReferenceEditorComboWithBrowseButton;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -73,9 +73,8 @@ public class IntroduceParameterObjectDialog extends RefactoringDialog {
|
||||
private JCheckBox keepMethodAsDelegate;
|
||||
private ReferenceEditorComboWithBrowseButton packageTextField;
|
||||
private ReferenceEditorComboWithBrowseButton existingClassField;
|
||||
private JPanel myVisibilityComponent;
|
||||
private JCheckBox myGenerateAccessorsCheckBox;
|
||||
private VisibilityPanel myVisibilityPanel;
|
||||
private JCheckBox myEscalateVisibilityCheckBox;
|
||||
private static final String RECENTS_KEY = "IntroduceParameterObject.RECENTS_KEY";
|
||||
private static final String EXISTING_KEY = "IntroduceParameterObject.EXISTING_KEY";
|
||||
|
||||
@@ -126,19 +125,17 @@ public class IntroduceParameterObjectDialog extends RefactoringDialog {
|
||||
useExistingClassButton.addActionListener(listener);
|
||||
createNewClassButton.addActionListener(listener);
|
||||
myCreateInnerClassRadioButton.addActionListener(listener);
|
||||
myGenerateAccessorsCheckBox.setSelected(true);
|
||||
myEscalateVisibilityCheckBox.setSelected(true);
|
||||
toggleRadioEnablement();
|
||||
|
||||
myVisibilityPanel = new VisibilityPanel(true, true);
|
||||
myVisibilityPanel.setVisibility(null);
|
||||
myVisibilityComponent.add(myVisibilityPanel, BorderLayout.WEST);
|
||||
}
|
||||
|
||||
private void toggleRadioEnablement() {
|
||||
enableGenerateAccessors();
|
||||
UIUtil.setEnabled(myUseExistingPanel, useExistingClassButton.isSelected(), true);
|
||||
UIUtil.setEnabled(myCreateNewClassPanel, createNewClassButton.isSelected(), true);
|
||||
UIUtil.setEnabled(myInnerClassPanel, myCreateInnerClassRadioButton.isSelected(), true);
|
||||
validateButtons();
|
||||
enableGenerateAccessors();
|
||||
}
|
||||
|
||||
protected String getDimensionServiceKey() {
|
||||
@@ -169,10 +166,12 @@ public class IntroduceParameterObjectDialog extends RefactoringDialog {
|
||||
parameters.add(data);
|
||||
}
|
||||
}
|
||||
final String newVisibility =
|
||||
myEscalateVisibilityCheckBox.isEnabled() && myEscalateVisibilityCheckBox.isSelected() ? VisibilityUtil.ESCALATE_VISIBILITY : null;
|
||||
invokeRefactoring(new IntroduceParameterObjectProcessor(className, packageName, sourceMethod,
|
||||
parameters.toArray(new ParameterTablePanel.VariableData[parameters.size()]),
|
||||
keepMethod, useExistingClass,
|
||||
createInnerClass, myVisibilityPanel.getVisibility(), myGenerateAccessorsCheckBox.isSelected()));
|
||||
createInnerClass, newVisibility, myGenerateAccessorsCheckBox.isSelected()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -331,5 +330,6 @@ public class IntroduceParameterObjectDialog extends RefactoringDialog {
|
||||
}
|
||||
}
|
||||
myGenerateAccessorsCheckBox.setEnabled(existingNotALibraryClass);
|
||||
myEscalateVisibilityCheckBox.setEnabled(existingNotALibraryClass);
|
||||
}
|
||||
}
|
||||
|
||||
+31
-31
@@ -33,7 +33,7 @@
|
||||
</component>
|
||||
<grid id="79318" layout-manager="GridBagLayout">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="6" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag top="10" left="0" bottom="0" right="0" weightx="0.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
@@ -48,18 +48,9 @@
|
||||
<text value="&Create new class"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2b175" class="javax.swing.JRadioButton" binding="useExistingClassButton">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag top="10" left="0" bottom="0" right="0" weightx="1.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Use existing class"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="57543" binding="myCreateNewClassPanel" layout-manager="GridBagLayout">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="6" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag top="0" left="20" bottom="0" right="0" weightx="1.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
@@ -104,7 +95,7 @@
|
||||
</grid>
|
||||
<grid id="37fbd" binding="myUseExistingPanel" layout-manager="GridBagLayout">
|
||||
<constraints>
|
||||
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="5" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag top="0" left="20" bottom="0" right="0" weightx="1.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
@@ -126,6 +117,24 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="286f3" class="javax.swing.JCheckBox" binding="myGenerateAccessorsCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<gridbag weightx="0.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Generate accessors"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="97fed" class="javax.swing.JCheckBox" binding="myEscalateVisibilityCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<gridbag weightx="0.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Escalate visibility"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="3eb4" class="javax.swing.JRadioButton" binding="myCreateInnerClassRadioButton" default-binding="true">
|
||||
@@ -139,7 +148,7 @@
|
||||
</component>
|
||||
<grid id="9a2f8" binding="myInnerClassPanel" layout-manager="GridBagLayout">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag top="0" left="20" bottom="0" right="0" weightx="0.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
@@ -166,6 +175,15 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="2b175" class="javax.swing.JRadioButton" binding="useExistingClassButton">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag top="10" left="0" bottom="0" right="0" weightx="1.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Use existing class"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="783a4" binding="myParamsPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
@@ -186,24 +204,6 @@
|
||||
<text value="Keep method as &delegate"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="d3a44" binding="myVisibilityComponent" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="6" column="3" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<gridbag top="10" left="0" bottom="0" right="0" weightx="0.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="286f3" class="javax.swing.JCheckBox" binding="myGenerateAccessorsCheckBox" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<gridbag weightx="0.0" weighty="0.0"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Generate accessors"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
+4
-5
@@ -41,7 +41,6 @@ import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewDescriptor;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -163,6 +162,10 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
|
||||
for (PsiMethod siblingMethod : overridingMethods) {
|
||||
findUsagesForMethod(siblingMethod, usages);
|
||||
}
|
||||
|
||||
if (myNewVisibility != null) {
|
||||
usages.add(new BeanClassVisibilityUsageInfo(existingClass, usages.toArray(new UsageInfo[usages.size()]), myNewVisibility, myExistingClassCompatibleConstructor));
|
||||
}
|
||||
}
|
||||
|
||||
private void findUsagesForMethod(PsiMethod overridingMethod, List<FixableUsageInfo> usages) {
|
||||
@@ -217,10 +220,6 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
|
||||
final PsiClass psiClass = buildClass();
|
||||
if (psiClass != null) {
|
||||
super.performRefactoring(usageInfos);
|
||||
VisibilityUtil.fixVisibility(usageInfos, psiClass, myNewVisibility);
|
||||
if (myExistingClassCompatibleConstructor != null) {
|
||||
VisibilityUtil.fixVisibility(usageInfos, myExistingClassCompatibleConstructor, myNewVisibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* User: anna
|
||||
* Date: 03-Nov-2009
|
||||
*/
|
||||
package com.intellij.refactoring.introduceparameterobject.usageInfo;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.refactoring.util.FixableUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
|
||||
public class BeanClassVisibilityUsageInfo extends FixableUsageInfo {
|
||||
private PsiClass existingClass;
|
||||
private UsageInfo[] usages;
|
||||
private String myNewVisibility;
|
||||
private PsiMethod myExistingClassCompatibleConstructor;
|
||||
|
||||
public BeanClassVisibilityUsageInfo(PsiClass existingClass,
|
||||
UsageInfo[] usages,
|
||||
String newVisibility,
|
||||
PsiMethod existingClassCompatibleConstructor) {
|
||||
super(existingClass);
|
||||
this.existingClass = existingClass;
|
||||
this.usages = usages;
|
||||
myNewVisibility = newVisibility;
|
||||
myExistingClassCompatibleConstructor = existingClassCompatibleConstructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixUsage() throws IncorrectOperationException {
|
||||
VisibilityUtil.fixVisibility(usages, existingClass, myNewVisibility);
|
||||
if (myExistingClassCompatibleConstructor != null) {
|
||||
VisibilityUtil.fixVisibility(usages, myExistingClassCompatibleConstructor, myNewVisibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user