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-2006 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: package org.netbeans.modules.refactoring.spi.impl;
043:
044: import java.text.MessageFormat;
045: import java.util.ResourceBundle;
046: import javax.swing.event.ChangeListener;
047: import org.netbeans.modules.refactoring.api.AbstractRefactoring;
048: import org.netbeans.modules.refactoring.api.Problem;
049: import org.netbeans.modules.refactoring.api.SafeDeleteRefactoring;
050: import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
051: import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
052: import org.openide.util.HelpCtx;
053: import org.openide.util.NbBundle;
054: import org.openide.util.lookup.Lookups;
055:
056: /**
057: * A CustomRefactoringUI subclass that represents Safe Delete
058: * @author Bharath Ravikumar
059: */
060: public class SafeDeleteUI<T> implements RefactoringUI {
061:
062: private final T[] elementsToDelete;
063:
064: private final SafeDeleteRefactoring refactoring;
065:
066: private SafeDeletePanel panel;
067:
068: private ResourceBundle bundle;
069:
070: /**
071: * Creates a new instance of SafeDeleteUI
072: * @param selectedElements An array of selected Elements that need to be
073: * safely deleted
074: */
075: public SafeDeleteUI(T[] selectedElements) {
076: this .elementsToDelete = selectedElements;
077: refactoring = new SafeDeleteRefactoring(Lookups
078: .fixed(elementsToDelete));
079: }
080:
081: /**
082: * Delegates to the fastCheckParameters of the underlying
083: * refactoring
084: * @return Returns the result of fastCheckParameters of the
085: * underlying refactoring
086: */
087: public org.netbeans.modules.refactoring.api.Problem checkParameters() {
088: return refactoring.fastCheckParameters();
089: }
090:
091: public String getDescription() {
092: return NbBundle.getMessage(SafeDeleteUI.class, "LBL_SafeDel"); // NOI18N
093: }
094:
095: public org.openide.util.HelpCtx getHelpCtx() {
096:
097: return new HelpCtx(SafeDeleteUI.class.getName());
098: }
099:
100: public String getName() {
101:
102: return NbBundle.getMessage(SafeDeleteUI.class, "LBL_SafeDel"); // NOI18N
103: }
104:
105: public CustomRefactoringPanel getPanel(ChangeListener parent) {
106: //TODO:Do you want to just use Arrays.asList?
107: if (panel == null)
108: panel = new SafeDeletePanel();
109: return panel;
110: }
111:
112: public AbstractRefactoring getRefactoring() {
113:
114: return refactoring;
115: }
116:
117: public boolean hasParameters() {
118:
119: return false;
120: }
121:
122: /**
123: * Returns false, since this refactoring is not a query.
124: * @return false
125: */
126: public boolean isQuery() {
127: return false;
128: }
129:
130: public Problem setParameters() {
131: return refactoring.checkParameters();
132: }
133:
134: //Helper methods------------------
135:
136: private String getString(String key) {
137: if (bundle == null) {
138: bundle = NbBundle.getBundle(SafeDeleteUI.class);
139: }
140: return bundle.getString(key);
141: }
142:
143: private String getString(String key, Object value) {
144: return new MessageFormat(getString(key))
145: .format(new Object[] { value });
146: }
147:
148: }
|