|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.refactoring.ui; import java.lang.Integer; import java.text.MessageFormat; import java.util.Collection; import java.util.Iterator; import java.util.List; import javax.jmi.reflect.RefObject; import javax.swing.JPanel; import javax.swing.table.DefaultTableModel; import org.netbeans.jmi.javamodel.JavaClass; import org.netbeans.jmi.javamodel.Method; import org.netbeans.modules.refactoring.api.Problem; import org.netbeans.modules.refactoring.api.AbstractRefactoring; import org.netbeans.modules.refactoring.api.ChangeParameters; import org.netbeans.modules.refactoring.api.ui.ParametersPanel; import org.netbeans.modules.refactoring.api.ui.RefactoringUI; import org.netbeans.modules.refactoring.api.ChangeParameters.ParameterInfo; import org.netbeans.jmi.javamodel.BehavioralFeature; import org.netbeans.jmi.javamodel.CallableFeature; import org.netbeans.jmi.javamodel.JavaModelPackage; import org.netbeans.jmi.javamodel.Type; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; /** * * @author Pavel Flaska */ public class ChangeParametersUI implements RefactoringUI { RefObject refactoredObj; ChangeParametersPanel panel; ChangeParameters refactoring; /** Creates a new instance of ChangeMethodSignatureRefactoring */ public ChangeParametersUI(RefObject refactoredObj) { this.refactoring = new ChangeParameters(refactoredObj); this.refactoredObj = refactoredObj; } public String getDescription() { String msg = NbBundle.getMessage(ChangeParametersUI.class, "DSC_ChangeParsRootNode"); CallableFeature callable = ((CallableFeature) refactoredObj); boolean isMethod = callable instanceof Method; String name = isMethod ? callable.getName() : ((JavaClass) callable.getDeclaringClass()).getSimpleName(); return new MessageFormat(msg).format(new Object[] { name, NbBundle.getMessage(ChangeParametersUI.class, "DSC_ChangeParsRootNode" + (isMethod ? "Method" : "Constr")), panel.genDeclarationString() }); } public JPanel getPanel(ParametersPanel parent) { if (panel == null) { parent.setPreviewEnabled(true); panel = new ChangeParametersPanel(refactoredObj, parent); } return panel; } public AbstractRefactoring getRefactoring() { return refactoring; } public boolean isQuery() { return false; } private Problem setParameters(boolean checkOnly) { List data = (List) panel.getTableModel().getDataVector(); ChangeParameters.ParameterInfo[] paramList = new ChangeParameters.ParameterInfo[data.size()]; JavaModelPackage pckg = (JavaModelPackage) refactoredObj.refImmediatePackage(); int counter = 0; Problem problem = null; for (Iterator rowIt = data.iterator(); rowIt.hasNext(); ++counter) { List row = (List) rowIt.next(); int origIndex = ((Integer) row.get(3)).intValue(); String name = null; String defaultVal = null; Type type = null; if (origIndex == -1) { name = (String) row.get(0); type = pckg.getType().resolve((String) row.get(1)); defaultVal = (String) row.get(2); } paramList[counter] = new ChangeParameters.ParameterInfo(origIndex, name, type, defaultVal); } int modifier = panel.getModifier(); if (checkOnly) { problem = refactoring.checkParameters(paramList, modifier); } else { problem = refactoring.setParameters(paramList, modifier); } return problem; } public String getName() { return NbBundle.getMessage(ChangeParametersUI.class, "LBL_ChangeMethodSignature"); } public Problem checkParameters() { return setParameters(true); } public Problem setParameters() { return setParameters(false); } public boolean hasParameters() { return true; } public HelpCtx getHelpCtx() { return new HelpCtx(ChangeParametersUI.class); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.