This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 20323
Collapse All | Expand All

(-)core/src/org/netbeans/core/modules/ModuleDeleter.java (+42 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.core.modules;
15
16
import java.io.IOException;
17
import org.openide.modules.ModuleInfo;
18
19
/** <code>ModuleDeleter</code> deletes module's files from installation if possible.
20
 * Checks if all information about files are known and deletes file from disk.
21
 * This interface is implemented in <code>Autoupdate</code> module.
22
 * 
23
 * @since ???
24
 * @author Jiri Rechtacek
25
 */
26
public interface ModuleDeleter {
27
    
28
    /** Are all information about files of the given module known.
29
     * 
30
     * @param module 
31
     * @return true if info is available
32
     */
33
    public boolean canDelete (Module module);
34
    
35
    /** Deletes all module's file from installation.
36
     * 
37
     * @param module 
38
     * @throws java.io.IOException 
39
     */
40
    public void delete (Module module) throws IOException;
41
    
42
}
(-)core/src/org/netbeans/core/ui/ModuleBean.java (-5 / +5 lines)
Lines 546-552 Link Here
546
                        }
546
                        }
547
                    }
547
                    }
548
                    doDelete(toDelete);
548
                    doDelete(toDelete);
549
                    doDisable(toDisable);
549
                    doDisable(toDisable, true);
550
                    it = toMakeReloadable.iterator();
550
                    it = toMakeReloadable.iterator();
551
                    while (it.hasNext()) {
551
                    while (it.hasNext()) {
552
                        Module m = (Module)it.next();
552
                        Module m = (Module)it.next();
Lines 586-592 Link Here
586
            if (modules.isEmpty()) return;
586
            if (modules.isEmpty()) return;
587
            err.log("doDelete: " + modules);
587
            err.log("doDelete: " + modules);
588
            // Have to be turned off first:
588
            // Have to be turned off first:
589
            doDisable(modules);
589
            doDisable(modules, false);
590
            Iterator it = modules.iterator();
590
            Iterator it = modules.iterator();
591
            while (it.hasNext()) {
591
            while (it.hasNext()) {
592
                Module m = (Module)it.next();
592
                Module m = (Module)it.next();
Lines 609-615 Link Here
609
            }
609
            }
610
        }
610
        }
611
611
612
        private void doDisable(Set modules) {
612
        private void doDisable(Set modules, boolean cancelable) {
613
            if (modules.isEmpty()) return;
613
            if (modules.isEmpty()) return;
614
            err.log("doDisable: " + modules);
614
            err.log("doDisable: " + modules);
615
            SortedSet realModules = new TreeSet(this); // SortedSet<Module>
615
            SortedSet realModules = new TreeSet(this); // SortedSet<Module>
Lines 641-647 Link Here
641
                c.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ModuleBean.class, "ACSD_TITLE_disabling"));
641
                c.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ModuleBean.class, "ACSD_TITLE_disabling"));
642
                NotifyDescriptor d = new NotifyDescriptor.Confirmation(c,
642
                NotifyDescriptor d = new NotifyDescriptor.Confirmation(c,
643
                    NbBundle.getMessage(ModuleBean.class, "MB_TITLE_disabling"),
643
                    NbBundle.getMessage(ModuleBean.class, "MB_TITLE_disabling"),
644
                    NotifyDescriptor.OK_CANCEL_OPTION);
644
                    cancelable ? NotifyDescriptor.OK_CANCEL_OPTION : NotifyDescriptor.DEFAULT_OPTION);
645
                if (org.openide.DialogDisplayer.getDefault().notify(d) != NotifyDescriptor.OK_OPTION) {
645
                if (org.openide.DialogDisplayer.getDefault().notify(d) != NotifyDescriptor.OK_OPTION) {
646
                    // User refused.
646
                    // User refused.
647
                    // Fire changes again since modules are now wrong & need recalc.
647
                    // Fire changes again since modules are now wrong & need recalc.
Lines 778-784 Link Here
778
                            // Hmm, too complicated to deal with now. Skip it.
778
                            // Hmm, too complicated to deal with now. Skip it.
779
                            continue;
779
                            continue;
780
                        }
780
                        }
781
                        doDisable(Collections.singleton(old));
781
                        doDisable(Collections.singleton(old), true);
782
                        if (old.isEnabled()) {
782
                        if (old.isEnabled()) {
783
                            // Did not work for some reason, skip it.
783
                            // Did not work for some reason, skip it.
784
                            continue;
784
                            continue;
(-)core/src/org/netbeans/core/ui/ModuleNode.java (-1 / +29 lines)
Lines 43-48 Link Here
43
import javax.swing.KeyStroke;
43
import javax.swing.KeyStroke;
44
import javax.swing.AbstractAction;
44
import javax.swing.AbstractAction;
45
import org.netbeans.core.IDESettings;
45
import org.netbeans.core.IDESettings;
46
import org.netbeans.core.modules.ModuleDeleter;
46
import org.openide.ErrorManager;
47
import org.openide.ErrorManager;
47
import org.openide.actions.DeleteAction;
48
import org.openide.actions.DeleteAction;
48
import org.openide.actions.NewAction;
49
import org.openide.actions.NewAction;
Lines 332-341 Link Here
332
        }
333
        }
333
334
334
        public void destroy () {
335
        public void destroy () {
335
            item.delete();
336
            ModuleDeleter deleter = getModuleDeleter ();
337
            if (deleter != null) {
338
                // XXX: the item should be delete automatically when config/Modules/module.xml is removed
339
                item.delete ();
340
                try {
341
                    deleter.delete (item.getModule ());
342
                } catch (IOException ioe) {
343
                    ErrorManager.getDefault ().notify (ErrorManager.USER, ioe);                    
344
                }
345
            } else {
346
                item.delete();
347
            }
336
        }
348
        }
337
349
338
        public boolean canDestroy () {
350
        public boolean canDestroy () {
351
            ModuleDeleter deleter = getModuleDeleter ();
352
            if (deleter != null) {
353
                if (deleter.canDelete (item.getModule ())) {
354
                    return true;
355
                }
356
            }
339
            return item.getJar() != null;
357
            return item.getJar() != null;
340
        }
358
        }
341
359
Lines 1035-1038 Link Here
1035
        return ModuleBean.AllModulesBean.getDefault();
1053
        return ModuleBean.AllModulesBean.getDefault();
1036
    }
1054
    }
1037
1055
1056
    private static ModuleDeleter getModuleDeleter () {
1057
        ModuleDeleter deleter = (ModuleDeleter) Lookup.getDefault ().lookup (ModuleDeleter.class);
1058
        if (deleter != null) {
1059
            return deleter;
1060
        } else {
1061
            assert false : "Any ModuleDeleter should exist.";
1062
            return null;
1063
        }
1064
    }
1065
    
1038
}
1066
}
(-)core/src/org/netbeans/core/ui/ModuleSelectionPanel.form (-92 lines)
Removed Link Here
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<Form version="1.0" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <Properties>
5
    <Property name="name" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
6
      <ResourceString bundle="org/netbeans/core/ui/Bundle.properties" key="LBL_SetupWizardModuleInstallation" replaceFormat="NbBundle.getMessage(ModuleSelectionPanel.class, &quot;{key}&quot;)"/>
7
    </Property>
8
  </Properties>
9
  <AuxValues>
10
    <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
11
  </AuxValues>
12
13
  <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
14
  <SubComponents>
15
    <Component class="javax.swing.JLabel" name="tableLabel">
16
      <Properties>
17
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
18
          <Connection component="treeTableView" type="bean"/>
19
        </Property>
20
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
21
          <ResourceString bundle="org/netbeans/core/ui/Bundle.properties" key="LBL_SetupWizardCheckModules" replaceFormat="NbBundle.getMessage(ModuleSelectionPanel.class, &quot;{key}&quot;)"/>
22
        </Property>
23
      </Properties>
24
      <Constraints>
25
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
26
          <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="1" insetsBottom="5" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
27
        </Constraint>
28
      </Constraints>
29
    </Component>
30
    <Container class="org.openide.explorer.ExplorerPanel" name="explorerPanel">
31
      <Constraints>
32
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
33
          <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="11" insetsRight="0" anchor="10" weightX="1.0" weightY="1.0"/>
34
        </Constraint>
35
      </Constraints>
36
37
      <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
38
      <SubComponents>
39
        <Container class="org.openide.explorer.view.TreeTableView" name="treeTableView">
40
          <Constraints>
41
            <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
42
              <BorderConstraints direction="Center"/>
43
            </Constraint>
44
          </Constraints>
45
46
          <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
47
        </Container>
48
      </SubComponents>
49
    </Container>
50
    <Component class="javax.swing.JLabel" name="descriptionLabel">
51
      <Properties>
52
        <Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
53
          <Connection component="descriptionArea" type="bean"/>
54
        </Property>
55
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
56
          <ResourceString bundle="org/netbeans/core/ui/Bundle.properties" key="LBL_SetupWizardDescription" replaceFormat="NbBundle.getMessage(ModuleSelectionPanel.class, &quot;{key}&quot;)"/>
57
        </Property>
58
      </Properties>
59
      <Constraints>
60
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
61
          <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="1" insetsBottom="5" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
62
        </Constraint>
63
      </Constraints>
64
    </Component>
65
    <Container class="javax.swing.JScrollPane" name="descriptionPane">
66
      <Properties>
67
        <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
68
          <Dimension value="[22, 80]"/>
69
        </Property>
70
        <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
71
          <Dimension value="[50, 80]"/>
72
        </Property>
73
      </Properties>
74
      <Constraints>
75
        <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
76
          <GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
77
        </Constraint>
78
      </Constraints>
79
80
      <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
81
      <SubComponents>
82
        <Component class="javax.swing.JTextArea" name="descriptionArea">
83
          <Properties>
84
            <Property name="editable" type="boolean" value="false"/>
85
            <Property name="lineWrap" type="boolean" value="true"/>
86
            <Property name="wrapStyleWord" type="boolean" value="true"/>
87
          </Properties>
88
        </Component>
89
      </SubComponents>
90
    </Container>
91
  </SubComponents>
92
</Form>
(-)core/src/org/netbeans/core/ui/ModuleSelectionPanel.java (-324 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.core.ui;
15
16
import javax.swing.UIManager;
17
import javax.swing.plaf.basic.BasicBorders;
18
19
import javax.swing.UIManager;
20
import javax.swing.border.Border;
21
22
import javax.swing.*;
23
import javax.swing.event.*;
24
import java.util.*;
25
import java.awt.*;
26
import java.awt.Font;
27
import java.awt.font.LineMetrics;
28
import java.beans.PropertyChangeListener;
29
import java.beans.PropertyChangeEvent;
30
31
import org.openide.WizardDescriptor;
32
import org.openide.nodes.*;
33
import org.openide.util.NbBundle;
34
import org.openide.explorer.ExplorerManager;
35
import org.openide.cookies.InstanceCookie;
36
import java.io.IOException;
37
38
/** Module selection panel allows user to enable/disable modules in setup wizard
39
 *
40
 * @author cledantec, jrojcek, Jesse Glick
41
 */
42
public class ModuleSelectionPanel extends javax.swing.JPanel 
43
                                  implements PropertyChangeListener {
44
45
    /** See org.openide.WizardDescriptor.PROP_CONTENT_SELECTED_INDEX
46
     */
47
    private static final String PROP_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; // NOI18N
48
    /** See org.openide.WizardDescriptor.PROP_CONTENT_DATA
49
     */
50
    private static final String PROP_CONTENT_DATA = "WizardPanel_contentData"; // NOI18N
51
    
52
    // SetupWizard has to load it eagerly too, so no harm here.
53
    private final ModuleBean.AllModulesBean allModules = ModuleBean.AllModulesBean.getDefault();
54
    
55
    /** default size values */
56
    private static final int DEF_TREE_WIDTH = 320;
57
    private static final int DEF_0_COL_WIDTH = 60;
58
    private static final int DEF_1_COL_WIDTH = 150;
59
    private static final int DEF_HEIGHT = 250;
60
    
61
    /** Creates new form wizardFrame */
62
    public ModuleSelectionPanel() {
63
        putClientProperty(PROP_CONTENT_SELECTED_INDEX, new Integer(0));
64
        String name = NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardModuleInstallation");
65
        putClientProperty(PROP_CONTENT_DATA, new String[] { name });
66
        setName(name);
67
    }
68
    
69
    
70
    
71
    /** Avoid initializing GUI, and allModules, until needed. */
72
    public void addNotify() {
73
        super.addNotify();
74
        if (treeTableView != null) return;
75
        synchronized (getTreeLock()) {
76
77
            initComponents();
78
79
            treeTableView.setProperties(
80
                new Node.Property[]{
81
                    new PropertySupport.ReadWrite (
82
                        "enabled", // NOI18N
83
                        Boolean.TYPE,
84
                        org.openide.util.NbBundle.getMessage (ModuleNode.class, "PROP_modules_enabled"),
85
                        org.openide.util.NbBundle.getMessage (ModuleNode.class, "HINT_modules_enabled")
86
                    ) {
87
                        public Object getValue () {
88
                            return null;
89
                        }
90
91
                        public void setValue (Object o) {
92
                        }
93
                    },
94
                    new PropertySupport.ReadOnly (
95
                        "specificationVersion", // NOI18N
96
                        String.class,
97
                        org.openide.util.NbBundle.getMessage (ModuleNode.class, "PROP_modules_specversion"),
98
                        org.openide.util.NbBundle.getMessage (ModuleNode.class, "HINT_modules_specversion")
99
                    ) {
100
                        public Object getValue () {
101
                            return null;
102
                        }
103
                    }
104
                }
105
            );
106
            //Fix for NPE on WinXP L&F - either may be null - Tim
107
            Font f = UIManager.getFont("controlFont");
108
            Integer i = (Integer) UIManager.get("nbDefaultFontSize");
109
            if (i == null) {
110
                i = new Integer(11); //fudge the default if not present
111
            }
112
            if (f == null) {
113
                f = getFont();
114
            }
115
116
            // perform additional preferred size computations for larger fonts
117
            if (f.getSize() > i.intValue()) { // NOI18N
118
                sizeTTVCarefully();
119
            } else {
120
                // direct sizing for default situation
121
                treeTableView.setPreferredSize(
122
                    new Dimension (DEF_1_COL_WIDTH + DEF_0_COL_WIDTH + DEF_TREE_WIDTH,
123
                                   DEF_HEIGHT)
124
                );
125
                treeTableView.setTreePreferredWidth(DEF_TREE_WIDTH);
126
                treeTableView.setTableColumnPreferredWidth(0, DEF_0_COL_WIDTH);
127
                treeTableView.setTableColumnPreferredWidth(1, DEF_1_COL_WIDTH);
128
            }
129
            treeTableView.setPopupAllowed(false);
130
            treeTableView.setDefaultActionAllowed(false);
131
132
            // install proper border
133
            treeTableView.setBorder((Border)UIManager.get("Nb.ScrollPane.border")); // NOI18N
134
135
            manager = explorerPanel.getExplorerManager();
136
            ModuleNode node = new ModuleNode(true);
137
            manager.setRootContext(node);
138
139
            initAccessibility();
140
        }
141
    }
142
    
143
    /** Computes and sets right preferred sizes of TTV columns.
144
     * Sizes of columns are computed as maximum of default values and 
145
     * header text length. Size of tree is aproximate, grows linearly with
146
     * font size.
147
     */
148
    private void sizeTTVCarefully () {
149
        Font headerFont = (Font)UIManager.getDefaults().get("TableHeader.font");  // NOI18N
150
        Font tableFont = (Font)UIManager.getDefaults().get("Table.font");  // NOI18N
151
        FontMetrics headerFm = getFontMetrics(headerFont);
152
        
153
        int enabledColWidth = Math.max(DEF_0_COL_WIDTH, headerFm.stringWidth(
154
            NbBundle.getMessage (ModuleNode.class, "PROP_modules_enabled")) + 20
155
        );
156
        int specColWidth = Math.max(DEF_1_COL_WIDTH, headerFm.stringWidth(
157
            NbBundle.getMessage (ModuleNode.class, "PROP_modules_specversion")) + 20
158
        );
159
        int defFontSize = UIManager.getDefaults().getInt("nbDefaultFontSize");
160
        int treeWidth = DEF_TREE_WIDTH + 10 * (tableFont.getSize() - defFontSize);
161
        
162
        treeTableView.setPreferredSize(
163
            new Dimension (treeWidth + enabledColWidth + specColWidth,
164
                           DEF_HEIGHT + 10 * (tableFont.getSize() - defFontSize))
165
        );
166
        treeTableView.setTreePreferredWidth(treeWidth);
167
        treeTableView.setTableColumnPreferredWidth(0, enabledColWidth);
168
        treeTableView.setTableColumnPreferredWidth(1, specColWidth);
169
    }
170
171
    /** This method is called from within the constructor to
172
     * initialize the form.
173
     * WARNING: Do NOT modify this code. The content of this method is
174
     * always regenerated by the Form Editor.
175
     */
176
    private void initComponents() {//GEN-BEGIN:initComponents
177
        java.awt.GridBagConstraints gridBagConstraints;
178
179
        tableLabel = new javax.swing.JLabel();
180
        explorerPanel = new org.openide.explorer.ExplorerPanel();
181
        treeTableView = new org.openide.explorer.view.TreeTableView();
182
        descriptionLabel = new javax.swing.JLabel();
183
        descriptionPane = new javax.swing.JScrollPane();
184
        descriptionArea = new javax.swing.JTextArea();
185
186
        setLayout(new java.awt.GridBagLayout());
187
188
        setName(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardModuleInstallation"));
189
        tableLabel.setLabelFor(treeTableView);
190
        tableLabel.setText(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardCheckModules"));
191
        gridBagConstraints = new java.awt.GridBagConstraints();
192
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
193
        gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0);
194
        add(tableLabel, gridBagConstraints);
195
196
        explorerPanel.add(treeTableView, java.awt.BorderLayout.CENTER);
197
198
        gridBagConstraints = new java.awt.GridBagConstraints();
199
        gridBagConstraints.gridx = 0;
200
        gridBagConstraints.gridy = 1;
201
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
202
        gridBagConstraints.weightx = 1.0;
203
        gridBagConstraints.weighty = 1.0;
204
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 11, 0);
205
        add(explorerPanel, gridBagConstraints);
206
207
        descriptionLabel.setLabelFor(descriptionArea);
208
        descriptionLabel.setText(NbBundle.getMessage(ModuleSelectionPanel.class, "LBL_SetupWizardDescription"));
209
        gridBagConstraints = new java.awt.GridBagConstraints();
210
        gridBagConstraints.gridx = 0;
211
        gridBagConstraints.gridy = 2;
212
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
213
        gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0);
214
        add(descriptionLabel, gridBagConstraints);
215
216
        descriptionPane.setMinimumSize(new java.awt.Dimension(22, 80));
217
        descriptionPane.setPreferredSize(new java.awt.Dimension(50, 80));
218
        descriptionArea.setEditable(false);
219
        descriptionArea.setLineWrap(true);
220
        descriptionArea.setWrapStyleWord(true);
221
        descriptionPane.setViewportView(descriptionArea);
222
223
        gridBagConstraints = new java.awt.GridBagConstraints();
224
        gridBagConstraints.gridx = 0;
225
        gridBagConstraints.gridy = 3;
226
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
227
        add(descriptionPane, gridBagConstraints);
228
229
    }//GEN-END:initComponents
230
231
    private void prevButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevButtonActionPerformed
232
        // Add your handling code here:
233
    }//GEN-LAST:event_prevButtonActionPerformed
234
235
    // Variables declaration - do not modify//GEN-BEGIN:variables
236
    private javax.swing.JTextArea descriptionArea;
237
    private javax.swing.JLabel descriptionLabel;
238
    private javax.swing.JScrollPane descriptionPane;
239
    private org.openide.explorer.ExplorerPanel explorerPanel;
240
    private javax.swing.JLabel tableLabel;
241
    private org.openide.explorer.view.TreeTableView treeTableView;
242
    // End of variables declaration//GEN-END:variables
243
244
    private ExplorerManager manager;
245
    
246
    /** Handling of property changes in node structure and setup wizard descriptor
247
     */
248
    public void propertyChange(PropertyChangeEvent evt) {
249
        if ((evt.getSource() == manager) 
250
            && (manager.PROP_SELECTED_NODES.equals(evt.getPropertyName()))) {
251
                
252
            Node[] nodes = manager.getSelectedNodes();
253
            String text = ""; // NOI18N
254
            if (nodes.length == 1) {
255
                InstanceCookie inst = (InstanceCookie)nodes[0].getCookie(InstanceCookie.class);
256
                if (inst != null) {
257
                    try {
258
                        if (inst.instanceClass() == ModuleBean.class) {
259
                            ModuleBean bean = (ModuleBean)inst.instanceCreate();
260
                            text = bean.getLongDescription();
261
                        }
262
                    } catch (IOException ioe) {
263
                        // ignore
264
                    } catch (ClassNotFoundException cnfe) {
265
                        // ignore
266
                    }
267
                }
268
            }
269
            descriptionArea.setText(text);
270
            descriptionArea.setCaretPosition(0);
271
        } else if ((evt.getSource() instanceof WizardDescriptor) 
272
            && (WizardDescriptor.PROP_VALUE.equals(evt.getPropertyName()))) {
273
                
274
            WizardDescriptor wd = (WizardDescriptor)evt.getSource();
275
            if ((wd.getValue() == wd.CANCEL_OPTION) || (wd.getValue() == wd.CLOSED_OPTION)) {
276
                wd.removePropertyChangeListener(this);
277
                allModules.cancel();
278
            } else if (wd.getValue() == wd.FINISH_OPTION) {
279
                wd.removePropertyChangeListener(this);
280
                allModules.resume();
281
            }
282
        }
283
    }
284
    
285
286
    /** Initialize accesibility
287
     */
288
    public void initAccessibility(){
289
290
        java.util.ResourceBundle b = NbBundle.getBundle(this.getClass());
291
        
292
        this.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_ModuleSelectionPanel"));
293
        
294
        tableLabel.setDisplayedMnemonic(b.getString("LBL_SetupWizardCheckModules_MNE").charAt(0));
295
        tableLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_tableLabel"));
296
        
297
        descriptionLabel.setDisplayedMnemonic(b.getString("LBL_SetupWizardDescription_MNE").charAt(0));
298
        descriptionLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACSD_descriptionLabel")); 
299
    }
300
    
301
    public void initFromSettings(Object settings) {
302
        if (settings instanceof WizardDescriptor) {
303
            ((WizardDescriptor)settings).addPropertyChangeListener(this);
304
        }
305
        addNotify();
306
        manager.addPropertyChangeListener(this);
307
        allModules.pause();
308
309
    }
310
    /** Provides the wizard panel with the opportunity to update the
311
    * settings with its current customized state.
312
    * Rather than updating its settings with every change in the GUI, it should collect them,
313
    * and then only save them when requested to by this method.
314
    * Also, the original settings passed to {@link #readSettings} should not be modified (mutated);
315
    * rather, the (copy) passed in here should be mutated according to the collected changes.
316
    * This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>.
317
    * @param settings the object representing a settings of the wizard
318
    */
319
    public void storeSettings (Object settings) {
320
        manager.removePropertyChangeListener(this);
321
    }
322
323
    
324
}
(-)core/src/org/netbeans/core/ui/ModuleSelectionWizardPanel.java (-105 lines)
Removed Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.core.ui;
15
16
import java.awt.Component;
17
import javax.swing.event.ChangeListener;
18
19
import org.openide.WizardDescriptor;
20
import org.openide.util.HelpCtx;
21
22
/** Module selection panel allows user to enable/disable modules in setup wizard
23
 *
24
 * @author Vincent Brabant, cledantec, jrojcek, Jesse Glick
25
 */
26
public class ModuleSelectionWizardPanel implements WizardDescriptor.FinishPanel {
27
28
    /** aggregation, instance of UI component of this wizard panel */
29
    private ModuleSelectionPanel panelUI;
30
31
    /** Creates new form wizardFrame */
32
    public ModuleSelectionWizardPanel() {
33
    }
34
    
35
    /** Get the component displayed in this panel.
36
    * @return the component
37
    */
38
    public Component getComponent () {
39
        return getPanelUI();
40
    }
41
42
    /** Help for this panel.
43
    * When the panel is active, this is used as the help for the wizard dialog.
44
    * @return the help or <code>null</code> if no help is supplied
45
    */
46
    public HelpCtx getHelp () {
47
        // #44551 - remove help Id
48
        //return new HelpCtx("setupwizard.moduleselection"); // NOI18N
49
        return null;
50
    }
51
52
    /** Provides the wizard panel with the current data--either
53
    * the default data or already-modified settings, if the user used the previous and/or next buttons.
54
    * This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>.
55
    * @param settings the object representing wizard panel state, as originally supplied to
56
    * {@link WizardDescriptor#WizardDescriptor(WizardDescriptor.Iterator,Object)}
57
    */
58
    
59
    public void readSettings (Object settings) {
60
        panelUI.initFromSettings(settings);
61
    }
62
63
    /** Provides the wizard panel with the opportunity to update the
64
    * settings with its current customized state.
65
    * Rather than updating its settings with every change in the GUI, it should collect them,
66
    * and then only save them when requested to by this method.
67
    * Also, the original settings passed to {@link #readSettings} should not be modified (mutated);
68
    * rather, the (copy) passed in here should be mutated according to the collected changes.
69
    * This method can be called multiple times on one instance of <code>WizardDescriptor.Panel</code>.
70
    * @param settings the object representing a settings of the wizard
71
    */
72
    public void storeSettings (Object settings) {
73
        panelUI.storeSettings(settings);
74
    }
75
76
    /** Test whether the panel is finished and it is safe to proceed to the next one.
77
    * If the panel is valid, the "Next" (or "Finish") button will be enabled.
78
    * @return <code>true</code> if the user has entered satisfactory information
79
    */
80
    public boolean isValid () {
81
        return true;
82
    }
83
    
84
    /** Add a listener to changes of the panel's validity.
85
    * @param l the listener to add
86
    * @see #isValid
87
    */
88
    public void addChangeListener (ChangeListener l) {
89
    }
90
91
    /** Remove a listener to changes of the panel's validity.
92
    * @param l the listener to remove
93
    */
94
    public void removeChangeListener (ChangeListener l) {
95
    }
96
97
    /** Accessor for UI component */
98
    private ModuleSelectionPanel getPanelUI() {
99
        if (panelUI == null) {
100
            panelUI = new ModuleSelectionPanel();
101
        }
102
        return panelUI;
103
    }
104
    
105
}
(-)core/ui/src/org/netbeans/core/ui/resources/layer.xml (-1 lines)
Lines 400-406 Link Here
400
            <file name="org-netbeans-core-ui-IDESettingsWizardPanel.instance">
400
            <file name="org-netbeans-core-ui-IDESettingsWizardPanel.instance">
401
                <attr name="basic" boolvalue="true" />
401
                <attr name="basic" boolvalue="true" />
402
            </file>
402
            </file>
403
            <file name="org-netbeans-core-ui-ModuleSelectionWizardPanel.instance" />
404
        </folder>
403
        </folder>
405
     </folder>    
404
     </folder>    
406
    
405
    
(-)autoupdate/libsrc/org/netbeans/updater/UpdateTracking.java (+1 lines)
Lines 46-51 Link Here
46
    private static final String ATTR_CRC = "crc"; // NOI18N
46
    private static final String ATTR_CRC = "crc"; // NOI18N
47
    
47
    
48
    private static final String NBM_ORIGIN = "nbm"; // NOI18N
48
    private static final String NBM_ORIGIN = "nbm"; // NOI18N
49
    // XXX: used also in org.netbeans.modules.autoupate.ModuleDeleterImpl
49
    private static final String INST_ORIGIN = "updater"; // NOI18N
50
    private static final String INST_ORIGIN = "updater"; // NOI18N
50
51
51
    /** Platform dependent file name separator */
52
    /** Platform dependent file name separator */
(-)autoupdate/src/META-INF/services/org.netbeans.core.modules.ModuleDeleter (+1 lines)
Added Link Here
1
org.netbeans.modules.autoupdate.ModuleDeleterImpl
(-)autoupdate/src/org/netbeans/modules/autoupdate/ModuleDeleterImpl.java (+226 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.autoupdate;
15
16
import org.netbeans.core.modules.Module;
17
import org.netbeans.core.modules.ModuleDeleter;
18
import org.openide.filesystems.FileUtil;
19
import org.openide.modules.InstalledFileLocator;
20
import org.openide.util.RequestProcessor;
21
import org.openide.xml.XMLUtil;
22
import org.openide.ErrorManager;
23
24
import java.io.File;
25
import java.io.FileInputStream;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.util.HashSet;
29
import java.util.Iterator;
30
import java.util.Set;
31
32
import org.w3c.dom.Document;
33
import org.w3c.dom.Element;
34
import org.w3c.dom.NamedNodeMap;
35
import org.w3c.dom.Node;
36
import org.w3c.dom.NodeList;
37
import org.xml.sax.InputSource;
38
import org.xml.sax.SAXException;
39
40
41
/** Control if the module's file can be deleted and can delete them from disk.
42
 * <p> Deletes all files what are installed together with given module, info about
43
 * these files read from <code>update_tracking</code> file corresponed to the module.
44
 * If this <code>update_tracking</code> doesn't exist the files cannot be deleted.
45
 * The Deleter waits until the module is enabled before start delete its files.
46
 * <br>
47
 * <p>The method are called from <code>org.netbeans.core.ModuleNode</code>.
48
 *
49
 * @author  Jiri Rechtacek
50
 */
51
public final class ModuleDeleterImpl implements ModuleDeleter {
52
53
    private static final String ELEMENT_MODULE = "module"; // NOI18N
54
    private static final String ELEMENT_VERSION = "module_version"; // NOI18N
55
    private static final String ATTR_ORIGIN = "origin"; // NOI18N
56
    private static final String ATTR_LAST = "last"; // NOI18N
57
    private static final String ATTR_FILE_NAME = "name"; // NOI18N
58
    private static final String UPDATE_TRACKING = "update_tracking"; // NOI18N
59
    private static final String INST_ORIGIN = "updater"; // NOI18N
60
    private static final boolean ONLY_FROM_AUTOUPDATE = false;
61
    
62
    private ErrorManager err = ErrorManager.getDefault ().getInstance ("org.netbeans.modules.autoupdate.ModuleDeleterImpl"); // NOI18N
63
    
64
    public boolean canDelete (Module module) {
65
        if (module.isFixed ()) {
66
            err.log ("Cannot delete module because module " + module.getCodeName () + " isFixed.");
67
        }
68
        return !module.isFixed () && findUpdateTracking (module, ONLY_FROM_AUTOUPDATE);
69
    }
70
    
71
    public void delete (Module module) throws IOException {
72
        if (module == null) {
73
            throw new IllegalArgumentException ("Module argument cannot be null.");
74
        }
75
        
76
        Runnable runRemoveModuleFiles = new RemoveFilesPerformer (module);
77
        RequestProcessor.getDefault ().post (runRemoveModuleFiles);
78
    }
79
80
    private File locateUpdateTracking (Module m) {
81
        String fileNameToFind = UPDATE_TRACKING + File.separator + m.getCodeNameBase ().replace ('.', '-') + ".xml"; // NOI18N
82
        return InstalledFileLocator.getDefault ().locate (fileNameToFind, m.getCodeNameBase (), false);
83
    }
84
    
85
    private void removeModuleFiles (Module m) throws IOException {
86
        File updateTracking = null;
87
        while ((updateTracking = locateUpdateTracking (m)) != null) {
88
            removeModuleFilesInCluster (m, updateTracking);
89
        }
90
    }
91
    
92
    private boolean findUpdateTracking (Module module, boolean checkIfFromAutoupdate) {
93
        File updateTracking = locateUpdateTracking (module);
94
        if (updateTracking.exists ()) {
95
            //err.log ("Find UPDATE_TRACKING: " + updateTracking + " found.");
96
            if (checkIfFromAutoupdate) {
97
                boolean isFromAutoupdate = fromAutoupdate (getModuleConfiguration (updateTracking));
98
                err.log ("Is Module " + module.getCodeName () + " installed by AutoUpdate? " + isFromAutoupdate);
99
                return isFromAutoupdate;
100
            } else {
101
                return true;
102
            }
103
        } else {
104
            err.log ("Cannot delete module " + module.getCodeName () + " because no update_tracking file found.");
105
            return false;
106
        }
107
    }
108
            
109
    private boolean fromAutoupdate (Node moduleNode) {
110
        Node attrOrigin = moduleNode.getAttributes ().getNamedItem (ATTR_ORIGIN);
111
        assert attrOrigin != null : "ELEMENT_VERSION must contain ATTR_ORIGIN attribute.";
112
        String origin = attrOrigin.getNodeValue ();
113
        return INST_ORIGIN.equals (origin);
114
    }
115
    
116
    private void removeModuleFilesInCluster (Module module, File updateTracking) throws IOException {
117
        err.log ("Read update_tracking " + updateTracking + " file.");
118
        Set/*<String>*/ moduleFiles = readModuleFiles (getModuleConfiguration (updateTracking));
119
        String configFile = "config" + File.separator + "Modules" + File.separator + module.getCodeNameBase ().replace ('.', '-') + ".xml"; // NOI18N
120
        if (moduleFiles.contains (configFile)) {
121
            File file = InstalledFileLocator.getDefault ().locate (configFile, module.getCodeNameBase (), false);
122
            //assert file != null : "File " + configFile + " is located in module " + module.getDisplayName () + " cluster.";
123
            //assert file.exists () : "File " + file + " exists.";
124
            if (file != null && file.exists ()) {
125
                err.log ("Config File " + file + " is deleted.");
126
                FileUtil.toFileObject (file).delete ();
127
            } else {
128
                err.log ("Warning: Confing File " + configFile + " doesn't exist!");
129
            }
130
        }
131
        Iterator it = moduleFiles.iterator ();
132
        while (it.hasNext ()) {
133
            String fileName = (String) it.next ();
134
            if (fileName.equals (configFile)) {
135
                continue;
136
            }
137
            File file = InstalledFileLocator.getDefault ().locate (fileName, module.getCodeNameBase (), false);
138
            assert file != null : "File " + configFile + " is located in module " + module.getDisplayName () + " cluster.";
139
            assert file.exists () : "File " + file + " exists.";
140
            if (file.exists ()) {
141
                err.log ("File " + file + " is deleted.");
142
                FileUtil.toFileObject (file).delete ();
143
            } else {
144
                err.log ("Warning: File " + file + " doesn't exist!");
145
            }
146
        }
147
        FileUtil.toFileObject (updateTracking).delete ();
148
        err.log ("File " + updateTracking + " is deleted.");
149
    }
150
    
151
    private Node getModuleConfiguration (File moduleUpdateTracking) {
152
        Document document = null;
153
        InputStream is;
154
        try {
155
            is = new FileInputStream (moduleUpdateTracking);
156
            InputSource xmlInputSource = new InputSource (is);
157
            document = XMLUtil.parse (xmlInputSource, false, false, null, org.openide.xml.EntityCatalog.getDefault ());
158
            if (is != null) {
159
                is.close ();
160
            }
161
        } catch (SAXException saxe) {
162
            ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, saxe);
163
            return null;
164
        } catch (IOException ioe) {
165
            ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ioe);
166
        }
167
168
        assert document.getDocumentElement () != null : "File " + moduleUpdateTracking + " must contain <module> element.";
169
        return getModuleElement (document.getDocumentElement ());
170
    }
171
    
172
    private Node getModuleElement (Element element) {
173
        Node lastElement = null;
174
        assert ELEMENT_MODULE.equals (element.getTagName ()) : "The root element is: " + ELEMENT_MODULE + " but was: " + element.getTagName ();
175
        NodeList listModuleVersions = element.getElementsByTagName (ELEMENT_VERSION);
176
        for (int i = 0; i < listModuleVersions.getLength (); i++) {
177
            lastElement = getModuleLastVersion (listModuleVersions.item (i));
178
            if (lastElement != null) {
179
                break;
180
            }
181
        }
182
        return lastElement;
183
    }
184
    
185
    private Node getModuleLastVersion (Node version) {
186
        Node attrLast = version.getAttributes ().getNamedItem (ATTR_LAST);
187
        assert attrLast != null : "ELEMENT_VERSION must contain ATTR_LAST attribute.";
188
        if (Boolean.valueOf (attrLast.getNodeValue ()).booleanValue ()) {
189
            return version;
190
        } else {
191
            return null;
192
        }
193
    }
194
    
195
    private Set/*<String>*/ readModuleFiles (Node version) {
196
        Set/*<String>*/ files = new HashSet ();
197
        NodeList fileNodes = version.getChildNodes ();
198
        for (int i = 0; i < fileNodes.getLength (); i++) {
199
            if (fileNodes.item (i).hasAttributes ()) {
200
                NamedNodeMap map = fileNodes.item (i).getAttributes ();
201
                files.add (map.getNamedItem (ATTR_FILE_NAME).getNodeValue ());
202
            }
203
        }
204
        return files;
205
    }
206
207
    private class RemoveFilesPerformer implements Runnable {
208
        Module m;
209
        public RemoveFilesPerformer (Module module) {
210
            m = module;
211
        }
212
        public void run () {
213
            if (m.isEnabled () && m.isValid ()) {
214
                err.log ("Module " + m.getDisplayName () + " is still valid, repost later.");
215
                RequestProcessor.getDefault ().post (this, 1000);
216
                return ;
217
            }
218
            try {
219
                err.log ("Module " + m.getDisplayName () + " has been disabled, its files can be removed.");
220
                removeModuleFiles (m);
221
            } catch (IOException ioe) {
222
                err.notify (ioe);
223
            }
224
        }
225
    }
226
}

Return to bug 20323