KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > qfs > apps > qflog > command > CommandEditRemove


1 // {{{ copyright
2

3 /********************************************************************
4  *
5  * $Id: CommandEditRemove.java,v 1.7 2000/07/05 14:07:44 gs Exp $
6  *
7  * The contents of this file are subject to the Mozilla Public
8  * License Version 1.1 (the "License"); you may not use this file
9  * except in compliance with the License. You may obtain a copy of
10  * the License at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14  * implied. See the License for the specific language governing
15  * rights and limitations under the License.
16  *
17  * The Original Code is qfs.de code.
18  *
19  * The Initial Developer of the Original Code is Gregor Schmid.
20  * Portions created by Gregor Schmid are
21  * Copyright (C) 1999 Quality First Software, Gregor Schmid.
22  * All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  *******************************************************************/

27
28 // }}}
29

30 package de.qfs.apps.qflog.command;
31
32 // {{{ imports
33

34 import java.awt.Component JavaDoc;
35 import java.awt.Frame JavaDoc;
36
37 import javax.swing.JOptionPane JavaDoc;
38 import javax.swing.JTable JavaDoc;
39
40 import de.qfs.lib.log.Log;
41 import de.qfs.lib.log.Logger;
42 import de.qfs.lib.command.CancelCommandException;
43 import de.qfs.lib.command.Command;
44 import de.qfs.lib.command.CommandException;
45 import de.qfs.lib.command.Invokable;
46 import de.qfs.lib.gui.FilteredAndSortedTableModel;
47 import de.qfs.lib.gui.Message;
48
49 import de.qfs.apps.qflog.logview.LogView;
50
51 import de.qfs.apps.qflog.Model;
52
53 // }}}
54

55 /**
56  * This Command saves the log entries from the listener in the selected row of
57  * the listener table into a log file.
58  *
59  * @author Gregor Schmid
60  * @version $Revision: 1.7 $
61  */

62 public class CommandEditRemove extends Command
63 implements Invokable
64 {
65     // {{{ variables
66

67     /**
68      * The Logger used for logging.
69      */

70     private final static Logger logger = new Logger (CommandEditRemove.class);
71
72     /**
73      * The parent Frame for the FileChooser.
74      */

75     private Frame JavaDoc parent;
76
77     /**
78      * The listener table.
79      */

80     private JTable JavaDoc table;
81
82     // }}}
83

84     // {{{ constructor
85

86     /**
87      * Create a new CommandEditRemove.
88      *
89      * @param source The source of the Command.
90      * @param parent A frame parent for messages.
91      * @param table The listener table.
92      */

93     public CommandEditRemove (Object JavaDoc source, Frame JavaDoc parent, JTable JavaDoc table)
94     {
95         super (source);
96         this.parent = parent;
97         this.table = table;
98     }
99
100     // }}}
101

102     // {{{ invoke
103

104     /**
105      * Invoke the command.
106      *
107      * @return Always null.
108      *
109      * @throws CommandException If the action is cancelled.
110      */

111     public Object JavaDoc invoke()
112         throws CommandException
113     {
114         if (logger.level >= Log.MTD) {
115             logger.log(Log.MTD, "invoke()", "");
116         }
117
118         int row = table.getSelectedRow();
119         if (row == -1) {
120             return null;
121         }
122         row = ((FilteredAndSortedTableModel) table.getModel())
123             .getMappedRow(row);
124
125         LogView view = Model.instance().getViewForRow(row);
126
127         if (view.getState() == view.STATE_CONNECTED) {
128             if (Message.showMessage(parent, "deleteConnected")
129                 != JOptionPane.OK_OPTION) {
130                 throw new CancelCommandException ();
131             }
132         }
133         Model.instance().removeView(row);
134         return null;
135     }
136
137     // }}}
138
}
139
Popular Tags