001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-200? Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.visualweb.project.jsf.ui;
021:
022: import java.awt.Component;
023: import java.util.Vector;
024: import javax.swing.event.ChangeListener;
025: import org.openide.WizardDescriptor;
026: import org.openide.filesystems.FileObject;
027: import org.openide.filesystems.Repository;
028: import org.openide.util.HelpCtx;
029: import org.openide.util.NbBundle;
030:
031: /**
032: * Wizard Panel that allows the user to select the Page Template
033: * @author Winston Prakash
034: */
035: public class PageLayoutChooserPanel implements WizardDescriptor.Panel,
036: WizardDescriptor.FinishablePanel {
037:
038: private PageLayoutChooserPanelGUI component;
039: Vector<PageLayoutData> pageLayoutList = new Vector<PageLayoutData>();
040: PageLayoutData selectedPageLayoutData;
041:
042: /** Creates a new instance of TemplatePanel */
043: public PageLayoutChooserPanel() {
044: component = null;
045: String pageLayoutsFolderName = "Templates/PageLayoutTemplates"; // NOI18N
046: FileObject pageLayoutsFolder = Repository.getDefault()
047: .getDefaultFileSystem().findResource(
048: pageLayoutsFolderName);
049: if (pageLayoutsFolder != null) {
050: FileObject[] pageLayouts = pageLayoutsFolder.getChildren();
051:
052: for (FileObject template : pageLayouts) {
053: PageLayoutData templateData = new PageLayoutData(
054: template);
055: if (templateData.isPageLayoutTemplate()) {
056: pageLayoutList.add(new PageLayoutData(template));
057: }
058: }
059: pageLayoutList = sortPosition(pageLayoutList);
060: }
061: }
062:
063: void setSelectedPageLayout(PageLayoutData selPageLayoutdata) {
064: selectedPageLayoutData = selPageLayoutdata;
065: }
066:
067: PageLayoutData getSelectedPageLayout() {
068: return selectedPageLayoutData;
069: }
070:
071: // Not a very effective algorithm for sorting. Ok for small array
072: private Vector sortPosition(Vector<PageLayoutData> pageLayoutList) {
073: Vector<PageLayoutData> sortedList = new Vector<PageLayoutData>();
074: for (PageLayoutData template : pageLayoutList) {
075: if (sortedList.isEmpty()) {
076: sortedList.add(template);
077: } else {
078: boolean inserted = false;
079: for (PageLayoutData template1 : sortedList) {
080: if (template.getPosition() < template1
081: .getPosition()) {
082: sortedList.insertElementAt(template, sortedList
083: .indexOf(template1));
084: inserted = true;
085: break;
086: }
087: }
088: if (!inserted) {
089: sortedList.add(template);
090: }
091: }
092: }
093: return sortedList;
094: }
095:
096: public boolean isPageLayoutsAvailable() {
097: return !pageLayoutList.isEmpty();
098: }
099:
100: Vector<PageLayoutData> getPageLayoutList() {
101: return pageLayoutList;
102: }
103:
104: public Component getComponent() {
105: if (component == null) {
106: component = new PageLayoutChooserPanelGUI(this );
107: }
108: return component;
109: }
110:
111: public HelpCtx getHelp() {
112: return new HelpCtx(PageLayoutChooserPanel.class);
113: }
114:
115: public void readSettings(Object settings) {
116:
117: }
118:
119: public boolean isFinishPanel() {
120: return true;
121: }
122:
123: public void storeSettings(Object settings) {
124: }
125:
126: public boolean isValid() {
127: return true;
128: }
129:
130: public void addChangeListener(ChangeListener l) {
131:
132: }
133:
134: public void removeChangeListener(ChangeListener l) {
135:
136: }
137: }
|