001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * UseSuperTypeRefactoringUI.java
044: *
045: * Created on June 20, 2005
046: *
047: */
048:
049: package org.netbeans.modules.refactoring.java.ui;
050:
051: import javax.swing.event.ChangeListener;
052: import org.netbeans.api.java.source.ElementHandle;
053: import org.netbeans.api.java.source.TreePathHandle;
054: import org.netbeans.modules.refactoring.api.AbstractRefactoring;
055: import org.netbeans.modules.refactoring.api.Problem;
056: import org.netbeans.modules.refactoring.java.RetoucheUtils;
057: import org.netbeans.modules.refactoring.java.api.UseSuperTypeRefactoring;
058: import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
059: import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
060: import org.openide.util.HelpCtx;
061: import org.openide.util.NbBundle;
062:
063: /**
064: * UseSuperTypeRefactoringUI.java
065: *
066: * Created on June 20, 2005, 7:23 PM
067: *
068: * @author Bharath Ravi Kumar
069: */
070: public class UseSuperTypeRefactoringUI implements RefactoringUI {
071:
072: private final TreePathHandle subType;
073: private final UseSuperTypeRefactoring refactoring;
074: private UseSuperTypePanel panel;
075: private ElementHandle super Type;
076:
077: /**
078: * Creates a new instance of UseSuperTypeRefactoringUI
079: * @param selectedElement The sub type being used
080: */
081: public UseSuperTypeRefactoringUI(TreePathHandle selectedElement) {
082: this .subType = selectedElement;
083: refactoring = new UseSuperTypeRefactoring(subType);
084: refactoring.getContext().add(
085: RetoucheUtils.getClasspathInfoFor(subType));
086: }
087:
088: /**
089: * Returns the name of the refactoring
090: * @return
091: */
092: public String getName() {
093: return NbBundle.getMessage(UseSuperTypeRefactoringUI.class,
094: "LBL_UseSuperType"); // NOI18N
095: }
096:
097: /**
098: * Returns the description of the refactoring
099: * @return
100: */
101: public String getDescription() {
102: return NbBundle.getMessage(UseSuperTypeRefactoringUI.class,
103: "DSC_UseSuperType", refactoring.getTypeElement()); // NOI18N
104: }
105:
106: /**
107: * return false
108: * @return
109: */
110: public boolean isQuery() {
111: return false;
112: }
113:
114: /**
115: * Sets the target super type on the underlying refactoring
116: * @return
117: */
118: public Problem setParameters() {
119: super Type = panel.getSuperType();
120: refactoring.setTargetSuperType(super Type);
121: return refactoring.checkParameters();
122: }
123:
124: /**
125: * Calls fastCheckParameters on the underlying refactoring
126: * @return
127: */
128: public Problem checkParameters() {
129: super Type = panel.getSuperType();
130: refactoring.setTargetSuperType(super Type);
131: return refactoring.fastCheckParameters();
132: }
133:
134: /**
135: * Returns true
136: * @return
137: */
138: public boolean hasParameters() {
139: return true;
140: }
141:
142: /**
143: * Returns the use super type refactoring
144: * @return
145: */
146: public AbstractRefactoring getRefactoring() {
147: return refactoring;
148: }
149:
150: /**
151: * Returns the relevant Helpctx
152: * @return
153: */
154: public HelpCtx getHelpCtx() {
155: return new HelpCtx(UseSuperTypeRefactoringUI.class.getName());
156: }
157:
158: public CustomRefactoringPanel getPanel(ChangeListener parent) {
159: if (panel == null)
160: panel = new UseSuperTypePanel(refactoring);
161: return panel;
162: }
163:
164: }
|