
org.codehaus.mevenide.webframeworks.AddFrameworkPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of j2ee Show documentation
Show all versions of j2ee Show documentation
Implementation of J2EE related APIs for the Maven2 project type.
The newest version!
/* ==========================================================================
* Copyright 2008 Mevenide Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =========================================================================
*/
package org.codehaus.mevenide.webframeworks;
import java.awt.Component;
import java.util.LinkedList;
import java.util.List;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import org.netbeans.modules.web.api.webmodule.WebFrameworks;
import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider;
/**
* Coied from netbeans.org's web.project
* @author Radko Najman
* @author Milos Kleint
*/
public class AddFrameworkPanel extends javax.swing.JPanel {
/** Creates new form AddFrameworkPanel */
public AddFrameworkPanel(List usedFrameworks) {
initComponents();
jListFrameworks.setCellRenderer(new FrameworksListCellRenderer());
createFrameworksList(usedFrameworks);
jListFrameworks.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
private void createFrameworksList(List usedFrameworks) {
List frameworks = WebFrameworks.getFrameworks();
DefaultListModel model = new DefaultListModel();
jListFrameworks.setModel(model);
for (int i = 0; i < frameworks.size(); i++) {
WebFrameworkProvider framework = (WebFrameworkProvider) frameworks.get(i);
if (usedFrameworks.size() == 0)
model.addElement(framework);
else {
boolean isUsed = false;
for (int j = 0; j < usedFrameworks.size(); j++)
if (((WebFrameworkProvider) usedFrameworks.get(j)).getName().equals(framework.getName())) {
isUsed = true;
break;
}
if (!isUsed)
model.addElement(framework);
}
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jListFrameworks = new javax.swing.JList();
jLabel1 = new javax.swing.JLabel();
jScrollPane1.setViewportView(jListFrameworks);
jLabel1.setLabelFor(jListFrameworks);
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AddFrameworkPanel.class, "LBL_Select_Framework")); // NOI18N
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
.add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE))
);
getAccessibleContext().setAccessibleDescription("null");
}// //GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JLabel jLabel1;
public javax.swing.JList jListFrameworks;
public javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
public List getSelectedFrameworks() {
List selectedFrameworks = new LinkedList();
DefaultListModel model = (DefaultListModel) jListFrameworks.getModel();
int[] indexes = jListFrameworks.getSelectedIndices();
for (int i = 0; i < indexes.length; i++)
selectedFrameworks.add(model.get(indexes[i]));
return selectedFrameworks;
}
public static class FrameworksListCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof WebFrameworkProvider) {
WebFrameworkProvider item = (WebFrameworkProvider) value;
return super.getListCellRendererComponent(list, item.getName(), index, isSelected, cellHasFocus);
} else
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy