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: package org.netbeans.modules.vmd.api.model.presenters.actions;
042:
043: import org.netbeans.modules.vmd.api.model.DesignComponent;
044: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
045: import org.openide.DialogDisplayer;
046: import org.openide.NotifyDescriptor;
047: import org.openide.util.NbBundle;
048:
049: import javax.swing.*;
050: import java.util.ArrayList;
051: import java.util.Collection;
052: import java.util.Collections;
053:
054: /**
055: * @author David Kaspar
056: */
057: class ConfirmDeletionPanel extends javax.swing.JPanel {
058:
059: public ConfirmDeletionPanel() {
060: initComponents();
061: }
062:
063: public static boolean show(
064: Collection<DesignComponent> selectedComponents,
065: Collection<DesignComponent> gatheredComponents) {
066: ConfirmDeletionPanel panel = new ConfirmDeletionPanel();
067: ArrayList<String> names;
068: DefaultListModel model;
069:
070: names = new ArrayList<String>();
071: for (DesignComponent component : selectedComponents) {
072: String name = InfoPresenter.getHtmlDisplayName(component);
073: if (name != null)
074: names.add(name);
075: }
076: Collections.sort(names);
077: model = new DefaultListModel();
078: for (String name : names)
079: model.addElement("<html>" + name); // NOI18N
080: panel.selected.setModel(model);
081:
082: names = new ArrayList<String>();
083: for (DesignComponent component : gatheredComponents) {
084: if (selectedComponents.contains(component))
085: continue;
086: if (DeleteSupport.isSilent(component))
087: continue;
088: String name = InfoPresenter.getHtmlDisplayName(component);
089: if (name != null)
090: names.add(name);
091: }
092: Collections.sort(names);
093: model = new DefaultListModel();
094: for (String name : names)
095: model.addElement("<html>" + name); // NOI18N
096: panel.dependent.setModel(model);
097:
098: panel.jLabel3.setVisible(model.size() > 0);
099: panel.jScrollPane2.setVisible(model.size() > 0);
100:
101: NotifyDescriptor descriptor = new NotifyDescriptor.Confirmation(
102: panel, NotifyDescriptor.YES_NO_OPTION);
103: descriptor.setTitle(NbBundle.getMessage(
104: ConfirmDeletionPanel.class, "TITLE_DeleteDialog")); // NOI18N
105:
106: DialogDisplayer.getDefault().notify(descriptor);
107: return NotifyDescriptor.YES_OPTION
108: .equals(descriptor.getValue());
109: }
110:
111: /** This method is called from within the constructor to
112: * initialize the form.
113: * WARNING: Do NOT modify this code. The content of this method is
114: * always regenerated by the Form Editor.
115: */
116: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
117: private void initComponents() {
118: java.awt.GridBagConstraints gridBagConstraints;
119:
120: javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
121: javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
122: selected = new javax.swing.JList();
123: javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
124: jLabel3 = new javax.swing.JLabel();
125: jScrollPane2 = new javax.swing.JScrollPane();
126: dependent = new javax.swing.JList();
127:
128: setLayout(new java.awt.GridBagLayout());
129:
130: jLabel1.setText(org.openide.util.NbBundle.getMessage(
131: ConfirmDeletionPanel.class,
132: "ConfirmDeletionPanel.jLabel1.text")); // NOI18N
133: gridBagConstraints = new java.awt.GridBagConstraints();
134: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
135: gridBagConstraints.weightx = 1.0;
136: add(jLabel1, gridBagConstraints);
137: jLabel1.getAccessibleContext().setAccessibleName(null);
138:
139: jScrollPane1.setViewportView(selected);
140:
141: gridBagConstraints = new java.awt.GridBagConstraints();
142: gridBagConstraints.gridx = 0;
143: gridBagConstraints.gridy = 2;
144: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
145: gridBagConstraints.weightx = 1.0;
146: gridBagConstraints.weighty = 1.0;
147: add(jScrollPane1, gridBagConstraints);
148:
149: jLabel2.setText(org.openide.util.NbBundle.getMessage(
150: ConfirmDeletionPanel.class,
151: "ConfirmDeletionPanel.jLabel2.text")); // NOI18N
152: gridBagConstraints = new java.awt.GridBagConstraints();
153: gridBagConstraints.gridx = 0;
154: gridBagConstraints.gridy = 1;
155: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
156: gridBagConstraints.weightx = 1.0;
157: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
158: add(jLabel2, gridBagConstraints);
159:
160: jLabel3.setText(org.openide.util.NbBundle.getMessage(
161: ConfirmDeletionPanel.class,
162: "ConfirmDeletionPanel.jLabel3.text")); // NOI18N
163: gridBagConstraints = new java.awt.GridBagConstraints();
164: gridBagConstraints.gridx = 0;
165: gridBagConstraints.gridy = 3;
166: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
167: gridBagConstraints.weightx = 1.0;
168: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
169: add(jLabel3, gridBagConstraints);
170:
171: jScrollPane2.setViewportView(dependent);
172:
173: gridBagConstraints = new java.awt.GridBagConstraints();
174: gridBagConstraints.gridx = 0;
175: gridBagConstraints.gridy = 4;
176: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
177: gridBagConstraints.weightx = 1.0;
178: gridBagConstraints.weighty = 1.0;
179: add(jScrollPane2, gridBagConstraints);
180: }// </editor-fold>//GEN-END:initComponents
181:
182: // Variables declaration - do not modify//GEN-BEGIN:variables
183: private javax.swing.JList dependent;
184: private javax.swing.JLabel jLabel3;
185: private javax.swing.JScrollPane jScrollPane2;
186: private javax.swing.JList selected;
187:
188: // End of variables declaration//GEN-END:variables
189: private static boolean isSilent(DesignComponent component) {
190: for (DeletePresenter presenter : component
191: .getPresenters(DeletePresenter.class))
192: if (presenter.isSilent())
193: return true;
194: return false;
195: }
196: }
|