001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.tool.archive.wizard;
024:
025: // ToolBox
026: import org.enhydra.tool.ToolBoxInfo;
027: import org.enhydra.tool.archive.ArchiveException;
028: import org.enhydra.tool.archive.Main;
029: import org.enhydra.tool.archive.JarPlan;
030: import org.enhydra.tool.common.PathHandle;
031: import org.enhydra.tool.common.SwingUtil;
032: import org.enhydra.tool.common.wizard.TBWizard;
033:
034: // JDK
035: import javax.swing.*;
036: import javax.swing.border.*;
037: import java.awt.*;
038: import java.awt.event.ActionEvent;
039: import java.awt.event.ActionListener;
040: import java.io.File;
041: import java.beans.*;
042: import java.util.ResourceBundle;
043:
044: /**
045: * The ArchiveDialog defines a dialog for presenting
046: * archive wizards.
047: */
048: public class ArchiveWizard extends TBWizard {
049:
050: //
051: private final static String ARCHIVE_TITLE = "Archive Wizard";
052:
053: //
054: transient private Icon largeIcon = null;
055: transient private ArchiveSelectionPanel selectionPanel = null;
056: transient private JarPlan plan = null;
057: transient private String workRoot = null;
058: transient private boolean mru = true;
059:
060: public ArchiveWizard() {
061: super ();
062: archiveInit();
063: }
064:
065: /**
066: * Get archive
067: *
068: * @return
069: * File object for archive.
070: *
071: */
072: public String getNewArchive() {
073: String newArchive = new String();
074:
075: if (getPlan() != null) {
076: newArchive = PathHandle.createPathString(getPlan()
077: .getArchivePath());
078: }
079: return newArchive;
080: }
081:
082: public JarPlan getPlan() {
083: return plan;
084: }
085:
086: public void setMostRecentlyUsed(boolean b) {
087: mru = b;
088: }
089:
090: public boolean isMostRecentlyUsed() {
091: return mru;
092: }
093:
094: public void setPlan(JarPlan p) throws ArchiveException {
095: plan = p;
096: ArchiveType type = null;
097: type = ArchiveType.createType(plan);
098: type.setMostRecentlyUsed(isMostRecentlyUsed());
099: getArchiveDeck().setSelection(type);
100: getArchiveDeck().setSelectionPageHidden(true);
101: }
102:
103: /**
104: * Set archive
105: *
106: * @param archive
107: * File object for archive.
108: *
109: */
110: public void readArchive(String archive) throws ArchiveException {
111: if (getArchiveDeck().getSelection() != null) {
112: getArchiveDeck().getSelection().readArchive(archive);
113: getArchiveDeck().readPlan();
114: }
115: }
116:
117: public void setWorkingRoot(String r) {
118: workRoot = PathHandle.createPathString(r);
119: System.setProperty("user.dir", getWorkingRoot());
120: }
121:
122: public String getWorkingRoot() {
123: if (workRoot == null) {
124: setWorkingRoot(System.getProperty("user.dir"));
125: }
126: return workRoot;
127: }
128:
129: // overrides TBWizard
130: public void back() {
131: if (getArchiveDeck().getPageIndex() == 1) {
132: setLargeIcon(largeIcon);
133: }
134: super .back();
135: }
136:
137: // overrides TBWizard
138: public void next() {
139: ArchiveType type = null;
140: if (getArchiveDeck().isSelectionPageShowing()) {
141: type = selectionPanel.getSelection();
142: try {
143: type.setMostRecentlyUsed(isMostRecentlyUsed());
144: getArchiveDeck().setSelection(type);
145: setLargeIcon(null);
146: getArchiveDeck().next();
147: } catch (ArchiveException e) {
148: JOptionPane.showMessageDialog(getInnerPanel(), e
149: .getMessage(), "Archive Wizard Error",
150: JOptionPane.ERROR_MESSAGE);
151: if (Main.debug) {
152: e.printStackTrace();
153: }
154: }
155: refreshButtons();
156: } else {
157: super .next();
158: }
159: }
160:
161: // override TBWizard
162: public void finish() {
163: try {
164: ArchiveType type = null;
165:
166: getArchiveDeck().writePlan();
167: type = getArchiveDeck().getSelection();
168: type.getPlan().setClassFiltering(true);
169: type.build();
170: setPlan(type.getPlan());
171: JOptionPane
172: .showMessageDialog(getInnerPanel(),
173: "Created archive:\n" + getNewArchive(),
174: "Archive Complete",
175: JOptionPane.INFORMATION_MESSAGE);
176: type.saveDefaults();
177: super .finish();
178: } catch (ArchiveException e) {
179: if (Main.debug) {
180: e.printStackTrace();
181: }
182: JOptionPane.showMessageDialog(getInnerPanel(), e
183: .getMessage(), "Archive Error",
184: JOptionPane.ERROR_MESSAGE);
185: }
186: }
187:
188: // implements TBWizard
189: public String getTitle() {
190: return ARCHIVE_TITLE;
191: }
192:
193: // implements TBWizard
194: protected String getProgressTitle() {
195: return "Archive Progress";
196: }
197:
198: /**
199: * Add listeners and other items that are not generated by
200: * the JBuilder designer.
201: */
202: private void archiveInit() {
203: ArchiveDeck newDeck = null;
204: ArchivePage page = null;
205:
206: largeIcon = getLargeIcon();
207: newDeck = new ArchiveDeck(this );
208: selectionPanel = new ArchiveSelectionPanel();
209: selectionPanel.setWizard(this );
210: setDeck(newDeck);
211: page = new ArchivePage();
212: page.setPageTitle(selectionPanel.getPageTitle());
213: page.setInstructions(selectionPanel.getInstructions());
214: page.add(selectionPanel);
215: addWizardPage(page);
216: }
217:
218: private ArchiveDeck getArchiveDeck() {
219: return (ArchiveDeck) getDeck();
220: }
221:
222: }
|