KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > gems > GemAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.ruby.rubyproject.gems;
20
21 import java.awt.Dialog JavaDoc;
22 import java.io.File JavaDoc;
23
24 import org.netbeans.modules.ruby.rubyproject.api.RubyInstallation;
25 import org.openide.DialogDescriptor;
26 import org.openide.DialogDisplayer;
27 import org.openide.NotifyDescriptor;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30 import org.openide.util.actions.CallableSystemAction;
31
32
33 public final class GemAction extends CallableSystemAction {
34     public void performAction() {
35         if (!RubyInstallation.getInstance().isValidRuby(true)) {
36             return;
37         }
38
39         String JavaDoc gem = RubyInstallation.getInstance().getGem();
40
41         if (!(new File JavaDoc(gem).exists())) {
42             String JavaDoc msg = NbBundle.getMessage(GemAction.class, "GemMissing", gem);
43             NotifyDescriptor nd =
44                 new NotifyDescriptor.Message(msg, NotifyDescriptor.Message.ERROR_MESSAGE);
45             DialogDisplayer.getDefault().notify(nd);
46
47             return;
48         }
49
50         InstalledGemsPanel customizer = new InstalledGemsPanel();
51         javax.swing.JButton JavaDoc close =
52             new javax.swing.JButton JavaDoc(NbBundle.getMessage(GemAction.class, "CTL_Close"));
53         close.getAccessibleContext()
54              .setAccessibleDescription(NbBundle.getMessage(GemAction.class, "AD_Close"));
55
56         DialogDescriptor descriptor =
57             new DialogDescriptor(customizer, NbBundle.getMessage(GemAction.class, "CTL_GemAction"),
58                 true, new Object JavaDoc[] { close }, close, DialogDescriptor.DEFAULT_ALIGN,
59                 new HelpCtx(GemAction.class), null); // NOI18N
60
Dialog JavaDoc dlg = null;
61
62         try {
63             dlg = DialogDisplayer.getDefault().createDialog(descriptor);
64             dlg.setVisible(true);
65         } finally {
66             if (dlg != null) {
67                 dlg.dispose();
68             }
69         }
70         
71         if (customizer.isModified()) {
72             RubyInstallation.getInstance().recomputeRoots();
73         }
74     }
75
76     public String JavaDoc getName() {
77         return NbBundle.getMessage(GemAction.class, "CTL_GemAction");
78     }
79
80     protected void initialize() {
81         super.initialize();
82         // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
83
putValue("noIconInMenu", Boolean.TRUE);
84     }
85
86     public HelpCtx getHelpCtx() {
87         return HelpCtx.DEFAULT_HELP;
88     }
89
90     protected boolean asynchronous() {
91         return false;
92     }
93 }
94
Popular Tags