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 / +27 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 && deleter.canDelete (item.getModule ())) {
338
                try {
339
                    deleter.delete (item.getModule ());
340
                } catch (IOException ioe) {
341
                    ErrorManager.getDefault ().notify (ErrorManager.USER, ioe);                    
342
                }
343
            } else {
344
                item.delete();
345
            }
336
        }
346
        }
337
347
338
        public boolean canDestroy () {
348
        public boolean canDestroy () {
349
            ModuleDeleter deleter = getModuleDeleter ();
350
            if (deleter != null) {
351
                if (deleter.canDelete (item.getModule ())) {
352
                    return true;
353
                }
354
            }
339
            return item.getJar() != null;
355
            return item.getJar() != null;
340
        }
356
        }
341
357
Lines 1035-1038 Link Here
1035
        return ModuleBean.AllModulesBean.getDefault();
1051
        return ModuleBean.AllModulesBean.getDefault();
1036
    }
1052
    }
1037
1053
1054
    private static ModuleDeleter getModuleDeleter () {
1055
        ModuleDeleter deleter = (ModuleDeleter) Lookup.getDefault ().lookup (ModuleDeleter.class);
1056
        if (deleter != null) {
1057
            return deleter;
1058
        } else {
1059
            assert false : "Any ModuleDeleter should exist.";
1060
            return null;
1061
        }
1062
    }
1063
    
1038
}
1064
}
(-)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 (+279 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
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.Repository;
33
34
import org.w3c.dom.Document;
35
import org.w3c.dom.Element;
36
import org.w3c.dom.NamedNodeMap;
37
import org.w3c.dom.Node;
38
import org.w3c.dom.NodeList;
39
import org.xml.sax.InputSource;
40
import org.xml.sax.SAXException;
41
42
43
/** Control if the module's file can be deleted and can delete them from disk.
44
 * <p> Deletes all files what are installed together with given module, info about
45
 * these files read from <code>update_tracking</code> file corresponed to the module.
46
 * If this <code>update_tracking</code> doesn't exist the files cannot be deleted.
47
 * The Deleter waits until the module is enabled before start delete its files.
48
 * <br>
49
 * <p>The method are called from <code>org.netbeans.core.ModuleNode</code>.
50
 *
51
 * @author  Jiri Rechtacek
52
 */
53
public final class ModuleDeleterImpl implements ModuleDeleter {
54
55
    private static final String ELEMENT_MODULE = "module"; // NOI18N
56
    private static final String ELEMENT_VERSION = "module_version"; // NOI18N
57
    private static final String ATTR_ORIGIN = "origin"; // NOI18N
58
    private static final String ATTR_LAST = "last"; // NOI18N
59
    private static final String ATTR_FILE_NAME = "name"; // NOI18N
60
    private static final String UPDATE_TRACKING = "update_tracking"; // NOI18N
61
    private static final String INST_ORIGIN = "updater"; // NOI18N
62
    private static final boolean ONLY_FROM_AUTOUPDATE = false;
63
    private static final int TIME_TO_CHECK = 2000;
64
    private static final int MAX_CHECKS_OF_STATE = 50;
65
    
66
    private ErrorManager err = ErrorManager.getDefault ().getInstance ("org.netbeans.modules.autoupdate.ModuleDeleterImpl"); // NOI18N
67
    
68
    public boolean canDelete (Module module) {
69
        if (module.isFixed ()) {
70
            err.log ("Cannot delete module because module " + module.getCodeName () + " isFixed.");
71
        }
72
        return !module.isFixed () && findUpdateTracking (module, ONLY_FROM_AUTOUPDATE);
73
    }
74
    
75
    public void delete (final Module module) throws IOException {
76
        if (module == null) {
77
            throw new IllegalArgumentException ("Module argument cannot be null.");
78
        }
79
        
80
        err.log ("Find and delete " + module.getCodeNameBase () + " module config file.");
81
        removeControlModuleFile (module);
82
        
83
        RequestProcessor.Task cleaner = RequestProcessor.getDefault ().create (new Runnable () {
84
            public void run () {
85
                try {
86
                    removeModuleFiles (module);
87
                } catch (IOException ioe) {
88
                    err.notify (ioe);
89
                }
90
            }
91
        });
92
        
93
        RequestProcessor.getDefault ().post (new ModuleStateChecker (module, cleaner), TIME_TO_CHECK);
94
    }
95
96
    private File locateControlFile (Module m) {
97
        String configFile = "config" + File.separator + "Modules" + File.separator + m.getCodeNameBase ().replace ('.', '-') + ".xml"; // NOI18N
98
        return InstalledFileLocator.getDefault ().locate (configFile, m.getCodeNameBase (), false);
99
    }
100
    
101
    private void removeControlModuleFile (Module m) throws IOException {
102
        File configFile = null;
103
        while ((configFile = locateControlFile (m)) != null) {
104
            if (configFile != null && configFile.exists ()) {
105
                err.log ("Try detele the config File " + configFile);
106
                FileUtil.toFileObject (configFile).delete ();
107
            } else {
108
                err.log ("Warning: Confing File " + configFile + " doesn't exist!");
109
            }
110
        }
111
        // XXX: the modules list should be delete automatically when config/Modules/module.xml is removed
112
        FileObject modulesRoot = Repository.getDefault ().getDefaultFileSystem ().findResource ("Modules"); // NOI18N
113
        err.log ("It's hack: Call refresh on " + modulesRoot + " file object.");
114
        if (modulesRoot != null) {
115
            modulesRoot.refresh ();
116
        }
117
        // end of hack
118
    }
119
    
120
    private File locateUpdateTracking (Module m) {
121
        String fileNameToFind = UPDATE_TRACKING + File.separator + m.getCodeNameBase ().replace ('.', '-') + ".xml"; // NOI18N
122
        return InstalledFileLocator.getDefault ().locate (fileNameToFind, m.getCodeNameBase (), false);
123
    }
124
    
125
    private boolean findUpdateTracking (Module module, boolean checkIfFromAutoupdate) {
126
        File updateTracking = locateUpdateTracking (module);
127
        if (updateTracking != null && updateTracking.exists ()) {
128
            //err.log ("Find UPDATE_TRACKING: " + updateTracking + " found.");
129
            // check the write permission
130
            if (!updateTracking.getParentFile ().canWrite ()) {
131
                err.log ("Cannot delete module " + module.getCodeName () + " because no write permission to directory " + updateTracking.getParent ());
132
                return false;
133
            }
134
            if (checkIfFromAutoupdate) {
135
                boolean isFromAutoupdate = fromAutoupdate (getModuleConfiguration (updateTracking));
136
                err.log ("Is Module " + module.getCodeName () + " installed by AutoUpdate? " + isFromAutoupdate);
137
                return isFromAutoupdate;
138
            } else {
139
                return true;
140
            }
141
        } else {
142
            err.log ("Cannot delete module " + module.getCodeName () + " because no update_tracking file found.");
143
            return false;
144
        }
145
    }
146
            
147
    private boolean fromAutoupdate (Node moduleNode) {
148
        Node attrOrigin = moduleNode.getAttributes ().getNamedItem (ATTR_ORIGIN);
149
        assert attrOrigin != null : "ELEMENT_VERSION must contain ATTR_ORIGIN attribute.";
150
        String origin = attrOrigin.getNodeValue ();
151
        return INST_ORIGIN.equals (origin);
152
    }
153
    
154
    private void removeModuleFiles (Module m) throws IOException {
155
        File updateTracking = null;
156
        while ((updateTracking = locateUpdateTracking (m)) != null) {
157
            removeModuleFilesInCluster (m, updateTracking);
158
        }
159
    }
160
    
161
    private void removeModuleFilesInCluster (Module module, File updateTracking) throws IOException {
162
        err.log ("Read update_tracking " + updateTracking + " file.");
163
        Set/*<String>*/ moduleFiles = readModuleFiles (getModuleConfiguration (updateTracking));
164
        String configFile = "config" + File.separator + "Modules" + File.separator + module.getCodeNameBase ().replace ('.', '-') + ".xml"; // NOI18N
165
        if (moduleFiles.contains (configFile)) {
166
            File file = InstalledFileLocator.getDefault ().locate (configFile, module.getCodeNameBase (), false);
167
            //assert file != null : "File " + configFile + " is located in module " + module.getCodeNameBase () + " cluster.";
168
            //assert file.exists () : "File " + file + " exists.";
169
            if (file != null && file.exists ()) {
170
                err.log ("Config File " + file + " is deleted.");
171
                FileUtil.toFileObject (file).delete ();
172
            } else {
173
                err.log ("Warning: Confing File " + configFile + " doesn't exist!");
174
            }
175
        }
176
        Iterator it = moduleFiles.iterator ();
177
        while (it.hasNext ()) {
178
            String fileName = (String) it.next ();
179
            if (fileName.equals (configFile)) {
180
                continue;
181
            }
182
            File file = InstalledFileLocator.getDefault ().locate (fileName, module.getCodeNameBase (), false);
183
            assert file != null : "File " + configFile + " is located in module " + module.getCodeNameBase () + " cluster.";
184
            assert file.exists () : "File " + file + " exists.";
185
            if (file.exists ()) {
186
                err.log ("File " + file + " is deleted.");
187
                FileUtil.toFileObject (file).delete ();
188
            } else {
189
                err.log ("Warning: File " + file + " doesn't exist!");
190
            }
191
        }
192
        FileUtil.toFileObject (updateTracking).delete ();
193
        err.log ("File " + updateTracking + " is deleted.");
194
    }
195
    
196
    private Node getModuleConfiguration (File moduleUpdateTracking) {
197
        Document document = null;
198
        InputStream is;
199
        try {
200
            is = new FileInputStream (moduleUpdateTracking);
201
            InputSource xmlInputSource = new InputSource (is);
202
            document = XMLUtil.parse (xmlInputSource, false, false, null, org.openide.xml.EntityCatalog.getDefault ());
203
            if (is != null) {
204
                is.close ();
205
            }
206
        } catch (SAXException saxe) {
207
            ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, saxe);
208
            return null;
209
        } catch (IOException ioe) {
210
            ErrorManager.getDefault ().notify (ErrorManager.INFORMATIONAL, ioe);
211
        }
212
213
        assert document.getDocumentElement () != null : "File " + moduleUpdateTracking + " must contain <module> element.";
214
        return getModuleElement (document.getDocumentElement ());
215
    }
216
    
217
    private Node getModuleElement (Element element) {
218
        Node lastElement = null;
219
        assert ELEMENT_MODULE.equals (element.getTagName ()) : "The root element is: " + ELEMENT_MODULE + " but was: " + element.getTagName ();
220
        NodeList listModuleVersions = element.getElementsByTagName (ELEMENT_VERSION);
221
        for (int i = 0; i < listModuleVersions.getLength (); i++) {
222
            lastElement = getModuleLastVersion (listModuleVersions.item (i));
223
            if (lastElement != null) {
224
                break;
225
            }
226
        }
227
        return lastElement;
228
    }
229
    
230
    private Node getModuleLastVersion (Node version) {
231
        Node attrLast = version.getAttributes ().getNamedItem (ATTR_LAST);
232
        assert attrLast != null : "ELEMENT_VERSION must contain ATTR_LAST attribute.";
233
        if (Boolean.valueOf (attrLast.getNodeValue ()).booleanValue ()) {
234
            return version;
235
        } else {
236
            return null;
237
        }
238
    }
239
    
240
    private Set/*<String>*/ readModuleFiles (Node version) {
241
        Set/*<String>*/ files = new HashSet ();
242
        NodeList fileNodes = version.getChildNodes ();
243
        for (int i = 0; i < fileNodes.getLength (); i++) {
244
            if (fileNodes.item (i).hasAttributes ()) {
245
                NamedNodeMap map = fileNodes.item (i).getAttributes ();
246
                files.add (map.getNamedItem (ATTR_FILE_NAME).getNodeValue ());
247
            }
248
        }
249
        return files;
250
    }
251
252
    private class ModuleStateChecker implements Runnable {
253
        RequestProcessor.Task cleaner;
254
        Module m;
255
        int checks;
256
        public ModuleStateChecker (Module module, RequestProcessor.Task filesCleaner) {
257
            cleaner = filesCleaner;
258
            m = module;
259
            checks = 0;
260
        }
261
        
262
        public void run () {
263
            checks ++;
264
            if (m.isEnabled () && m.isValid ()) {
265
                if (checks < MAX_CHECKS_OF_STATE) {
266
                    err.log ("Module " + m.getCodeNameBase () + " is still valid, repost later.");
267
                    RequestProcessor.getDefault ().post (this, TIME_TO_CHECK);
268
                } else {
269
                    err.log ("Warning: Module " + m.getCodeNameBase () + " is still valid but time-out. Task is terminated.");
270
                }
271
                return ;
272
            }
273
            
274
            // post clean task
275
            cleaner.run ();
276
        }
277
        
278
    }
279
}

Return to bug 20323