001: /*
002: * $RCSfile: OpenProductAction.java,v $
003: * @modification $Date: 2001/09/28 19:31:19 $
004: * @version $Id: OpenProductAction.java,v 1.1 2001/09/28 19:31:19 hfalk Exp $
005: *
006: */
007:
008: package com.memoire.vainstall.builder.action;
009:
010: import com.memoire.vainstall.VAGlobals;
011: import com.memoire.vainstall.builder.*;
012: import com.memoire.vainstall.builder.util.*;
013:
014: import java.io.File;
015: import java.util.Hashtable;
016: import javax.swing.JFileChooser;
017: import javax.swing.JOptionPane;
018:
019: /**
020: * This action opens an already saved project
021: *
022: * @see com.memoire.vainstall.builder.util.AbstractVAIBuilderAction
023: *
024: * @author Henrik Falk
025: * @version $Id: OpenProductAction.java,v 1.1 2001/09/28 19:31:19 hfalk Exp $
026: */
027: public class OpenProductAction extends AbstractVAIBuilderAction {
028:
029: /**
030: * Default constructor
031: */
032: public OpenProductAction() {
033: super ();
034: }
035:
036: /**
037: * Implements the runnit method
038: */
039: public void runnit() {
040:
041: // create filechooser
042: JFileChooser chooser = new JFileChooser();
043: chooser.setDialogType(JFileChooser.OPEN_DIALOG);
044: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
045:
046: // set current directory to ...
047: if (getModel().getLastOpenedProjectList().size() != 0) {
048: String file = (String) getModel()
049: .getLastOpenedProjectList().get(0);
050:
051: String super directory = file.substring(0, file
052: .lastIndexOf(File.separator));
053: String directory = super directory.substring(0,
054: super directory.lastIndexOf(File.separator));
055: System.out.println(directory);
056: chooser.setCurrentDirectory(new java.io.File(directory));
057: } else {
058: chooser.setCurrentDirectory(new java.io.File(System
059: .getProperty("user.dir")));
060: }
061:
062: // we only allow 'vainstall.xml' files to be valid
063: chooser.setAcceptAllFileFilterUsed(false);
064: VAIProjectFileFilter filter = new VAIProjectFileFilter();
065: chooser.addChoosableFileFilter(filter);
066:
067: // show filechooser
068: int retval = chooser.showOpenDialog(getController().getFrame());
069: if (retval == JFileChooser.APPROVE_OPTION) {
070: File theFile = chooser.getSelectedFile();
071: } else {
072: // return if the user pressed 'Cancel'
073: return;
074: }
075:
076: String fullName = chooser.getSelectedFile().getAbsolutePath();
077:
078: String projectDirectory = fullName.substring(0, fullName
079: .lastIndexOf(File.separator));
080:
081: // if product already opened then just get it into focus
082: Hashtable list = getController().getProductControllerList();
083: VAIProductController product = (VAIProductController) list
084: .get(projectDirectory);
085: if (product != null) {
086: try {
087: product.getFrame().setVisible(true);
088: product.getFrame().setSelected(true);
089: product.getFrame().setMaximum(true);
090: } catch (Exception exc) {
091: exc.printStackTrace();
092: return;
093: }
094: return;
095: }
096:
097: // load project
098: VAIProductController productController = new VAIProductController();
099: productController.getModel().setProductDirectory(
100: projectDirectory);
101: try {
102: productController.getModel().load();
103: } catch (VAIBuilderException exc) {
104: JOptionPane.showMessageDialog(getController().getFrame(),
105: exc.getMessageAsHtml(), VAGlobals.NAME,
106: JOptionPane.ERROR_MESSAGE);
107: return;
108: }
109: getController().addProduct(projectDirectory, productController);
110:
111: }
112: }
|