1 24 25 package org.objectweb.cjdbc.console.gui.objects; 26 27 import java.awt.Color ; 28 import java.awt.datatransfer.DataFlavor ; 29 import java.awt.datatransfer.Transferable ; 30 import java.awt.datatransfer.UnsupportedFlavorException ; 31 import java.awt.dnd.DnDConstants ; 32 import java.awt.dnd.DragSource ; 33 import java.io.IOException ; 34 35 import javax.management.InstanceNotFoundException ; 36 import javax.swing.SwingConstants ; 37 38 import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean; 39 import org.objectweb.cjdbc.console.gui.CjdbcGui; 40 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 41 import org.objectweb.cjdbc.console.gui.constants.GuiIcons; 42 import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener; 43 import org.objectweb.cjdbc.console.gui.popups.BackendPopUpMenu; 44 import org.objectweb.cjdbc.console.jmx.RmiJmxClient; 45 46 52 public class BackendObject extends AbstractGuiObject 53 implements 54 Transferable , 55 Cloneable 56 57 { 58 private String backendState; 59 private String database; 60 private String controllerName; 61 private DatabaseBackendMBean mbean; 62 private String user; 63 private String password; 64 private CjdbcGui gui; 65 private RmiJmxClient jmxClient; 66 private BackendPopUpMenu menu; 67 68 75 public DatabaseBackendMBean getMbean() throws InstanceNotFoundException , 76 IOException 77 { 78 jmxClient = (RmiJmxClient) gui.getJmxClients().get(controllerName); 79 user = gui.getGuiSession().getAuthenticatedDatabaseLogin(database); 80 password = gui.getGuiSession().getAuthenticatedDatabasePassword(database); 81 mbean = jmxClient.getDatabaseBackendProxy(database, getName(), user, 82 password); 83 return mbean; 84 } 85 86 97 public BackendObject(CjdbcGui gui, BackendTransferListener listener, 98 String database, String name, String controllerName) 99 throws InstanceNotFoundException , IOException 100 { 101 super(); 102 this.database = database; 103 this.controllerName = controllerName; 104 this.gui = gui; 105 setText(name); 106 setName(name); 107 this.menu = new BackendPopUpMenu(gui, this); 108 setBackground(Color.white); 109 setVerticalTextPosition(SwingConstants.BOTTOM); 110 111 getMbean(); 112 113 addMouseMotionListener(listener); 114 addMouseListener(listener); 115 addMouseListener(menu); 116 117 DragSource dragSource = DragSource.getDefaultDragSource(); 118 dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, listener); } 122 123 128 public String getState() 129 { 130 return backendState; 131 } 132 133 138 public void setState(String state) 139 { 140 this.backendState = state; 141 if (state.equals(GuiConstants.BACKEND_STATE_ENABLED)) 142 { 143 setIcon(GuiIcons.BACKEND_ENABLED_ICON); 144 menu.setEnabled(true); 145 menu.getBackendCheckpoint().setEnabled(false); 146 menu.getBackendCreate().setEnabled(true); 147 menu.getBackendRemove().setEnabled(false); 148 149 menu.getBackendEnable().setEnabled(false); 150 menu.getBackendDisable().setEnabled(true); 151 menu.getBackendBackup().setEnabled(true); 152 menu.getBackendRestore().setEnabled(false); 153 } 154 else if (state.equals(GuiConstants.BACKEND_STATE_DISABLED)) 155 { 156 setIcon(GuiIcons.BACKEND_DISABLED_ICON); 157 menu.getBackendCheckpoint().setEnabled(true); 158 menu.getBackendCreate().setEnabled(true); 159 menu.getBackendRemove().setEnabled(true); 160 161 menu.getBackendEnable().setEnabled(true); 162 menu.getBackendDisable().setEnabled(false); 163 menu.getBackendBackup().setEnabled(true); 164 menu.getBackendRestore().setEnabled(true); 165 } 166 else if (state.equals(GuiConstants.BACKEND_STATE_DISABLING)) 167 { 168 setIcon(GuiIcons.BACKEND_DISABLING_ICON); 169 menu.setEnabled(false); 170 } 171 else if (state.equals(GuiConstants.BACKEND_STATE_BACKUP)) 172 { 173 setIcon(GuiIcons.BACKEND_BACKUP_ICON); 174 menu.setEnabled(false); 175 } 176 else if (state.equals(GuiConstants.BACKEND_STATE_RESTORE)) 177 { 178 setIcon(GuiIcons.BACKEND_RESTORE_ICON); 179 menu.setEnabled(false); 180 } 181 else if (state.equals(GuiConstants.BACKEND_STATE_RECOVERY)) 182 { 183 setIcon(GuiIcons.BACKEND_STATE_RECOVERY); 184 menu.setEnabled(false); 185 } 186 } 187 188 191 public DataFlavor [] getTransferDataFlavors() 192 { 193 return new DataFlavor []{DataFlavor.stringFlavor, DataFlavor.plainTextFlavor}; 194 } 195 196 199 public boolean isDataFlavorSupported(DataFlavor flavor) 200 { 201 if (flavor.equals(DataFlavor.stringFlavor) 202 || flavor.equals(DataFlavor.plainTextFlavor)) 203 return true; 204 else 205 return false; 206 } 207 208 211 public Object getTransferData(DataFlavor flavor) 212 throws UnsupportedFlavorException , IOException 213 { 214 return this.getText(); 215 } 216 217 222 public String getDatabase() 223 { 224 return database; 225 } 226 227 232 public String getControllerName() 233 { 234 return controllerName; 235 } 236 237 242 public void setControllerName(String controllerName) 243 { 244 this.controllerName = controllerName; 245 } 246 247 250 public void setName(String name) 251 { 252 super.setName(name); 253 setText(name); 254 } 255 260 public RmiJmxClient getJmxClient() 261 { 262 return jmxClient; 263 } 264 } | Popular Tags |