001 // This file is part of the program FRYSK. 002 // 003 // Copyright 2005, Red Hat Inc. 004 // 005 // FRYSK is free software; you can redistribute it and/or modify it 006 // under the terms of the GNU General Public License as published by 007 // the Free Software Foundation; version 2 of the License. 008 // 009 // FRYSK is distributed in the hope that it will be useful, but 010 // WITHOUT ANY WARRANTY; without even the implied warranty of 011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 // General Public License for more details. 013 // type filter text 014 // You should have received a copy of the GNU General Public License 015 // along with FRYSK; if not, write to the Free Software Foundation, 016 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 017 // 018 // In addition, as a special exception, Red Hat, Inc. gives You the 019 // additional right to link the code of FRYSK with code not covered 020 // under the GNU General Public License ("Non-GPL Code") and to 021 // distribute linked combinations including the two, subject to the 022 // limitations in this paragraph. Non-GPL Code permitted under this 023 // exception must only link to the code of FRYSK through those well 024 // defined interfaces identified in the file named EXCEPTION found in 025 // the source code files (the "Approved Interfaces"). The files of 026 // Non-GPL Code may instantiate templates or use macros or inline 027 // functions from the Approved Interfaces without causing the 028 // resulting work to be covered by the GNU General Public 029 // License. Only Red Hat, Inc. may make changes or additions to the 030 // list of Approved Interfaces. You must obey the GNU General Public 031 // License in all respects for all of the FRYSK code and other code 032 // used in conjunction with FRYSK except the Non-GPL Code covered by 033 // this exception. If you modify this file, you may extend this 034 // exception to your version of the file, but you are not obligated to 035 // do so. If you do not wish to provide this exception without 036 // modification, you must delete this exception statement from your 037 // version and license this file solely under the GPL without 038 // exception. 039 040 041 package frysk.gui.monitor; 042 043 import org.gnu.gtk.Button; 044 import org.gnu.gtk.GtkStockItem; 045 import org.gnu.gtk.IconSize; 046 import org.gnu.gtk.Image; 047 import org.gnu.gtk.ToolTips; 048 import org.gnu.gtk.event.ButtonEvent; 049 import org.gnu.gtk.event.ButtonListener; 050 import org.gnu.gtk.event.ComboBoxEvent; 051 import org.gnu.gtk.event.ComboBoxListener; 052 import org.gnu.gtk.event.FocusEvent; 053 import org.gnu.gtk.event.FocusListener; 054 055 import frysk.gui.monitor.observers.ObserverRoot; 056 057 /** 058 * A widget that shows an observer item and allows the user to edit 059 * it. An observer item can either be a filter or an action. 060 */ 061 public abstract class ObserverItemRow 062 { 063 064 Combo combo; 065 066 SimpleComboBox itemsComboBox; 067 068 CompletingEntry argumentEntry; 069 070 Button addButton; 071 072 Button removeButton; 073 074 ObserverRoot observer; 075 076 String offendingArg; 077 078 protected ObserverItemsTable table; 079 080 ToolTips toolTips = new ToolTips(); 081 082 ObserverItemRow (ObserverItemsTable table, ObserverRoot observer, 083 Combo myCombo) 084 { 085 086 this.table = table; 087 this.combo = myCombo; 088 this.observer = observer; 089 090 argumentEntry = new CompletingEntry(); 091 if (combo != null) 092 { 093 String argument = ((LiaisonItem) combo.getFilter()).getArgument(); 094 if (argument == null) 095 { 096 argumentEntry.setSensitive(false); 097 } 098 else 099 { 100 argumentEntry.setText(argument); 101 } 102 } 103 else 104 { 105 argumentEntry.setText(""); 106 } 107 108 argumentEntry.addListener(new FocusListener() 109 { 110 public boolean focusEvent (FocusEvent event) 111 { 112 if (event.isOfType(FocusEvent.Type.FOCUS_OUT)) 113 { 114 apply(); 115 } 116 return false; 117 } 118 }); 119 120 removeButton = new Button(""); 121 removeButton.setImage(new Image(GtkStockItem.REMOVE, IconSize.BUTTON)); 122 removeButton.addListener(new ButtonListener() 123 { 124 public void buttonEvent (ButtonEvent event) 125 { 126 if (event.isOfType(ButtonEvent.Type.CLICK)) 127 { 128 itemsComboBox.setSelectedObject(null); 129 argumentEntry.setText(""); 130 if (ObserverItemRow.this.table.getIndexOfFinalRow() == 1) 131 { 132 if (combo != null && combo.isApplied()) 133 { 134 combo.unApply(); 135 } 136 removeButton.setSensitive(false); 137 } 138 else 139 { 140 if (combo != null && combo.isApplied()) 141 { 142 combo.unApply(); 143 } 144 ObserverItemRow.this.table.removeRow(ObserverItemRow.this); 145 } 146 } 147 } 148 }); 149 if (ObserverItemRow.this.table.getIndexOfFinalRow() == 1){ 150 removeButton.setSensitive(false); 151 } 152 153 addButton = new Button(""); 154 addButton.setImage(new Image(GtkStockItem.ADD, IconSize.BUTTON)); 155 addButton.addListener(new ButtonListener() 156 { 157 public void buttonEvent (ButtonEvent event) 158 { 159 if (event.isOfType(ButtonEvent.Type.CLICK)) 160 { 161 ObserverItemRow.this.table.addRow(null); 162 if(!removeButton.getSensitive()){ 163 removeButton.setSensitive(true); 164 } 165 } 166 } 167 }); 168 169 itemsComboBox = new SimpleComboBox(); 170 itemsComboBox.addListener(new ComboBoxListener() 171 { 172 public void comboBoxEvent (ComboBoxEvent event) 173 { 174 if (event.isOfType(ComboBoxEvent.Type.CHANGED)) 175 { 176 Combo newCombo = (Combo) itemsComboBox.getSelectedObject(); 177 178 if (combo != null && combo.isApplied()) 179 { 180 // unapply the previous combo 181 combo.unApply(); 182 } 183 // if another combo has been selected apply that one 184 if (newCombo != null) 185 { 186 combo = newCombo; 187 188 if(!removeButton.getSensitive()){ 189 removeButton.setSensitive(true); 190 } 191 192 toolTips.setTip(argumentEntry, combo.getToolTip(), ""); 193 194 ObservableLinkedList list = combo.getFilter().getArgumentCompletionList(); 195 if (list != null) 196 { 197 argumentEntry.watchList(list); 198 } 199 combo.apply(); 200 } 201 } 202 } 203 }); 204 205 } 206 207 public boolean apply () 208 { 209 if (combo == null) 210 { 211 // this FilterRow represents and unapplied filter 212 combo = (Combo) itemsComboBox.getSelectedObject(); 213 } 214 215 if (combo == null) 216 {// nothing was selected by user 217 return false; 218 } 219 if (! combo.isApplied()) 220 { 221 combo.apply(); 222 } 223 224 // if (((LiaisonItem) combo.getFilter()).setArgument(argumentEntry.getText()) 225 // || ((LiaisonItem) combo.getFilter()).needInfo == 0) 226 if (((LiaisonItem) combo.getFilter()).setArgument(argumentEntry.getText())) 227 return true; 228 else 229 { 230 //this.offendingArg = (((LiaisonItem) combo.getFilter()).getArgument()); 231 return false; 232 } 233 } 234 235 public void removeFromTable () 236 { 237 ObserverItemRow.this.table.remove(itemsComboBox); 238 ObserverItemRow.this.table.remove(argumentEntry); 239 ObserverItemRow.this.table.remove(addButton); 240 ObserverItemRow.this.table.remove(removeButton); 241 242 ObserverItemRow.this.table.showAll(); 243 } 244 245 public abstract void addToTable (); 246 247 public String getOffendingArg () 248 { 249 return this.offendingArg; 250 } 251 252 }