001: /*
002: * $RCSfile: ShowRequirementsAction.java,v $
003: * @modification $Date: 2002/12/16 13:23:45 $
004: * @version $Id: ShowRequirementsAction.java,v 1.2 2002/12/16 13:23:45 deniger 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.event.*;
013: import com.memoire.vainstall.builder.gui.ShowRequirementsFrame;
014: import com.memoire.vainstall.builder.util.*;
015:
016: import java.awt.Rectangle;
017: import java.awt.event.*;
018: import java.util.Enumeration;
019:
020: import javax.swing.*;
021: import javax.swing.event.*;
022:
023: /**
024: * This action shows a window in which required fields not
025: * yet filled out are shown.
026: *
027: * @see com.memoire.vainstall.builder.util.AbstractVAIBuilderAction
028: *
029: * @author Henrik Falk
030: * @version $Id: ShowRequirementsAction.java,v 1.2 2002/12/16 13:23:45 deniger Exp $
031: */
032: public class ShowRequirementsAction extends AbstractVAIBuilderAction
033: implements WindowListener, ListSelectionListener,
034: VAIBuilderListener {
035:
036: /**
037: * We keep a reference to the window to have only one opened window
038: * and keep track of the window bounds
039: */
040: ShowRequirementsFrame requirements;
041:
042: DefaultListModel emptyListModel = new DefaultListModel();
043:
044: /**
045: * Default constructor
046: */
047: public ShowRequirementsAction() {
048: super ();
049: }
050:
051: /**
052: * Implements the runnit method
053: */
054: public void runnit() {
055:
056: // if show before then restore window and show it
057: if (requirements != null) {
058: // requirements.setExtendedState(JFrame.NORMAL);
059: requirements.setVisible(true);
060: return;
061: }
062:
063: // create window and listen to windowDeactivated()
064: requirements = new ShowRequirementsFrame();
065: requirements.addWindowListener(this );
066:
067: // add listener for builder events
068: getModel().addVAIBuilderListener(this );
069:
070: if (getController().getActiveProductController() != null) {
071:
072: DefaultListModel model = getController()
073: .getActiveProductController().getModel()
074: .getRequiredListModel();
075:
076: requirements.getList().setModel(model);
077: if (model.size() > 0) {
078: requirements.getList().addListSelectionListener(this );
079: requirements.getList().setSelectedIndex(0);
080: }
081: }
082:
083: // set bounds from properties
084: if (getModel().getWindowList().get("ShowRequirementsFrame") == null) {
085: ((ShowRequirementsFrame) requirements).center();
086: } else {
087: requirements.setBounds((Rectangle) getModel()
088: .getWindowList().get("ShowRequirementsFrame"));
089: }
090:
091: requirements.setVisible(true);
092: }
093:
094: /**
095: * Method to handle events for the WindowListener interface.
096: * @param e java.awt.event.WindowEvent
097: */
098: public void windowActivated(java.awt.event.WindowEvent e) {
099: }
100:
101: /**
102: * Method to handle events for the WindowListener interface.
103: * @param e java.awt.event.WindowEvent
104: */
105: public void windowClosed(java.awt.event.WindowEvent e) {
106: }
107:
108: /**
109: * Method to handle events for the WindowListener interface.
110: * @param e java.awt.event.WindowEvent
111: */
112: public void windowClosing(java.awt.event.WindowEvent e) {
113: }
114:
115: /**
116: * Method to handle events for the WindowListener interface.
117: * @param e java.awt.event.WindowEvent
118: */
119: public void windowDeactivated(java.awt.event.WindowEvent e) {
120: getModel().getWindowList().put("ShowRequirementsFrame",
121: requirements.getBounds());
122: }
123:
124: /**
125: * Method to handle events for the WindowListener interface.
126: * @param e java.awt.event.WindowEvent
127: */
128: public void windowDeiconified(java.awt.event.WindowEvent e) {
129: }
130:
131: /**
132: * Method to handle events for the WindowListener interface.
133: * @param e java.awt.event.WindowEvent
134: */
135: public void windowIconified(java.awt.event.WindowEvent e) {
136: }
137:
138: /**
139: * Method to handle events for the WindowListener interface.
140: * @param e java.awt.event.WindowEvent
141: */
142: public void windowOpened(java.awt.event.WindowEvent e) {
143: }
144:
145: public void valueChanged(ListSelectionEvent evt) {
146:
147: if (((JList) evt.getSource()).getSelectedIndex() != -1) {
148: ProductRequirement req = (ProductRequirement) ((JList) evt
149: .getSource()).getSelectedValue();
150: requirements.getEditorPane().setText(req.getHelp());
151: } else {
152: requirements.getEditorPane().setText("");
153: }
154: }
155:
156: public void builderChanged(VAIBuilderEvent evt) {
157:
158: switch (evt.getType()) {
159: case VAIBuilderEvent.PROJECT_ACTIVATED:
160:
161: VAIProductController activeProductController = getController()
162: .getActiveProductController();
163:
164: if (activeProductController != null) {
165:
166: DefaultListModel model = activeProductController
167: .getModel().getRequiredListModel();
168: requirements.getList().setModel(model);
169: requirements.getList().addListSelectionListener(this );
170: if (model.size() > 0) {
171: requirements.getList().setSelectedIndex(0);
172: } else {
173: requirements.getEditorPane().setText("");
174: }
175: }
176:
177: break;
178: case VAIBuilderEvent.PROJECT_DEACTIVATED:
179:
180: requirements.getList().removeListSelectionListener(this );
181:
182: requirements.getList().setModel(emptyListModel);
183: requirements.getEditorPane().setText("");
184:
185: break;
186: }
187: }
188: }
|