001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.project.libraries.ui;
043:
044: import org.netbeans.api.project.libraries.*;
045: import org.netbeans.modules.project.libraries.ui.*;
046: import java.io.File;
047: import java.net.URL;
048: import java.util.ArrayList;
049: import java.util.List;
050: import javax.swing.DefaultComboBoxModel;
051: import org.netbeans.api.project.libraries.LibraryManager;
052: import org.netbeans.modules.project.libraries.LibraryAccessor;
053: import org.netbeans.spi.project.libraries.ArealLibraryProvider;
054: import org.netbeans.spi.project.libraries.LibraryStorageArea;
055: import org.netbeans.spi.project.libraries.support.LibrariesSupport;
056: import org.openide.util.Lookup;
057: import org.openide.util.NbBundle;
058:
059: /**
060: *
061: */
062: class AllLibrariesCustomizer extends javax.swing.JPanel {
063:
064: private org.netbeans.modules.project.libraries.ui.LibrariesCustomizer librariesCustomizer;
065:
066: /** Creates new form AllLibrariesCustomizer */
067: public AllLibrariesCustomizer() {
068: initComponents();
069: librariesCustomizer = new org.netbeans.modules.project.libraries.ui.LibrariesCustomizer(
070: null);
071: placeholder.add(librariesCustomizer);
072: initModel();
073: }
074:
075: public boolean apply() {
076: return librariesCustomizer.apply();
077: }
078:
079: private void initModel() {
080: List<String> items = new ArrayList<String>();
081: items.add(NbBundle.getMessage(AllLibrariesCustomizer.class,
082: "LABEL_Global_Libraries"));
083: for (LibraryManager man : LibraryManager.getOpenManagers()) {
084: if (man.getLocation() == null) {
085: continue;
086: }
087: items.add(LibrariesSupport.convertURLToFilePath(man
088: .getLocation()));
089: }
090: libraryManagerComboBox.setModel(new DefaultComboBoxModel(items
091: .toArray(new String[items.size()])));
092: }
093:
094: /** This method is called from within the constructor to
095: * initialize the form.
096: * WARNING: Do NOT modify this code. The content of this method is
097: * always regenerated by the Form Editor.
098: */
099: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
100: private void initComponents() {
101:
102: libraryManagerComboBox = new javax.swing.JComboBox();
103: placeholder = new javax.swing.JPanel();
104: jLabel1 = new javax.swing.JLabel();
105:
106: libraryManagerComboBox
107: .addActionListener(new java.awt.event.ActionListener() {
108: public void actionPerformed(
109: java.awt.event.ActionEvent evt) {
110: libraryManagerComboBoxActionPerformed(evt);
111: }
112: });
113:
114: placeholder.setLayout(new java.awt.BorderLayout());
115:
116: jLabel1.setText(java.text.MessageFormat.format(
117: org.openide.util.NbBundle.getMessage(
118: AllLibrariesCustomizer.class,
119: "AllLibrariesCustomizer.jLabel1.text"),
120: new Object[] {})); // NOI18N
121:
122: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
123: this );
124: this .setLayout(layout);
125: layout
126: .setHorizontalGroup(layout
127: .createParallelGroup(
128: org.jdesktop.layout.GroupLayout.LEADING)
129: .add(
130: org.jdesktop.layout.GroupLayout.TRAILING,
131: layout
132: .createSequentialGroup()
133: .addContainerGap()
134: .add(
135: layout
136: .createParallelGroup(
137: org.jdesktop.layout.GroupLayout.TRAILING)
138: .add(
139: org.jdesktop.layout.GroupLayout.LEADING,
140: placeholder,
141: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
142: 377,
143: Short.MAX_VALUE)
144: .add(
145: layout
146: .createSequentialGroup()
147: .add(
148: jLabel1)
149: .addPreferredGap(
150: org.jdesktop.layout.LayoutStyle.RELATED)
151: .add(
152: libraryManagerComboBox,
153: 0,
154: 289,
155: Short.MAX_VALUE)))
156: .addContainerGap()));
157: layout
158: .setVerticalGroup(layout
159: .createParallelGroup(
160: org.jdesktop.layout.GroupLayout.LEADING)
161: .add(
162: layout
163: .createSequentialGroup()
164: .addContainerGap()
165: .add(
166: layout
167: .createParallelGroup(
168: org.jdesktop.layout.GroupLayout.BASELINE)
169: .add(jLabel1)
170: .add(
171: libraryManagerComboBox,
172: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
173: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
174: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
175: .addPreferredGap(
176: org.jdesktop.layout.LayoutStyle.RELATED)
177: .add(
178: placeholder,
179: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
180: 230, Short.MAX_VALUE)));
181: }// </editor-fold>//GEN-END:initComponents
182:
183: private void libraryManagerComboBoxActionPerformed(
184: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_libraryManagerComboBoxActionPerformed
185: int index = libraryManagerComboBox.getSelectedIndex();
186: if (index == -1) {
187: return;
188: } else if (index == 0) {
189: librariesCustomizer.setLibraryStorageArea(null);
190: } else if (index > 0) {
191: URL u = LibrariesSupport
192: .convertFilePathToURL((String) libraryManagerComboBox
193: .getModel().getSelectedItem());
194: librariesCustomizer
195: .setLibraryStorageArea(findLibraryStorageArea(u));
196: }
197: }//GEN-LAST:event_libraryManagerComboBoxActionPerformed
198:
199: private LibraryStorageArea findLibraryStorageArea(URL u) {
200: for (ArealLibraryProvider alp : Lookup.getDefault().lookupAll(
201: ArealLibraryProvider.class)) {
202: for (LibraryStorageArea area : LibraryAccessor
203: .getOpenAreas(alp)) {
204: if (u.equals(area.getLocation())) {
205: return area;
206: }
207: }
208: }
209: return null;
210: }
211:
212: // Variables declaration - do not modify//GEN-BEGIN:variables
213: private javax.swing.JLabel jLabel1;
214: private javax.swing.JComboBox libraryManagerComboBox;
215: private javax.swing.JPanel placeholder;
216: // End of variables declaration//GEN-END:variables
217:
218: }
|