📄 adminmgr.java
字号:
*/
private void onlineConnect(ActionEvent evt) {
try {
// if online.
new OnlineConnection(this);
setConnected(true, "Connected - Online Mode");
} catch (Exception err) {
JOptionPane.showMessageDialog
(this, err.getMessage(), "Online Connection Error",
JOptionPane.ERROR_MESSAGE);
}
}
/**
* Connect to the database in offline mode. This action causes
* the file chooser to be displayed, and the user must select an existing
* database, or enter a new name to create a new database.
*
* All databases are suffixed with a ".db".
*
* @param evt The event that triggered this operation.
*
*/
private void offlineConnect(ActionEvent evt) {
try {
// if online.
new OfflineConnection(this);
setConnected(true, "Connected - OFFLine Mode");
} catch (Exception err) {
JOptionPane.showMessageDialog
(this, err.getMessage(), "Database Error",
JOptionPane.ERROR_MESSAGE);
}
}
/**
* Disconnect from a connected OpenJMSServer. Close the database, set the
* connected flag to false, stop displaying the OpenJMS folder.
*
* @param evt The event that triggered this operation.
*
*/
private void disconnect(ActionEvent evt) {
try {
AdminConnection.instance().close();
setConnected(false, null);
} catch (Exception e) {
JOptionPane.showMessageDialog
(this, e.getMessage(), "Database Close Error",
JOptionPane.ERROR_MESSAGE);
}
}
/**
* A conveniance routine to open/close all database connections,
* and fix up the display.
*
* <P>When disconnecting, turn off the root, destroy all Gui objects
* close the db connection, turn off all context sensitive menus,
* disable disconnection menu and enable connection. Set the message
* text to disconnected.
*
* @param c a flag inidication if this is a connection or disconnection.
*
*/
private void setConnected(boolean c, String st) {
if (c) {
serverProperties_.setRootVisible(true);
((OpenJMSServer)
(serverProperties_.getModel().getRoot())).displayContexts();
connections_.setEnabled(false);
refresh_.setEnabled(true);
disconnect_.setEnabled(true);
messageArea_.setForeground(java.awt.Color.green.darker().darker());
messageArea_.setText(st);
connected_ = true;
} else {
serverProperties_.setRootVisible(false);
OpenJMSServer root =
(OpenJMSServer) serverProperties_.getModel().getRoot();
root.removeAllChildren();
DefaultTreeModel model =
(DefaultTreeModel) serverProperties_.getModel();
model.nodeStructureChanged((DefaultMutableTreeNode) root);
connections_.setEnabled(true);
refresh_.setEnabled(false);
disconnect_.setEnabled(false);
messageArea_.setForeground(java.awt.Color.red);
messageArea_.setText("Not Connected");
connected_ = false;
}
}
/**
* Set up all Action menu callbacks, and mouse events for the tree and its
* nodes. Check all mose 2 key presses on a node, select the node,
* then call the nodes appropriate display methos to display its
* specific popup menus.
*
*/
private void setupCallbacks() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
exitForm(evt);
}
}
);
serverProperties_.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if (!connected_) {
return;
}
if (SwingUtilities.isRightMouseButton(e)) {
int selRow = serverProperties_.getRowForLocation
(e.getX(), e.getY());
serverProperties_.setSelectionRow(selRow);
Object loc =
serverProperties_.getLastSelectedPathComponent();
if (loc instanceof OpenJMSNode) {
OpenJMSNode node = (OpenJMSNode) loc;
node.displayCommands
(serverProperties_.getRowBounds(selRow));
} else if (loc instanceof OpenJMSServer) {
((OpenJMSServer) loc).displayCommands
(serverProperties_.getRowBounds(selRow));
}
}
}
}
);
serverProperties_.addTreeExpansionListener(new TreeExpansionListener() {
public void treeCollapsed(TreeExpansionEvent e) {
// todo Anything.....
}
public void treeExpanded(TreeExpansionEvent e) {
TreePath path = e.getPath();
Object loc = path.getLastPathComponent();
if (loc instanceof OpenJMSNode) {
OpenJMSNode node = (OpenJMSNode) loc;
node.update();
}
}
}
);
exit_.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
exitAdmin(evt);
}
}
);
refresh_.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
refresh(evt);
}
}
);
online_.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
onlineConnect(evt);
}
}
);
offline_.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
offlineConnect(evt);
}
}
);
disconnect_.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
disconnect(evt);
}
}
);
}
/**
* The main entry point for this admin gui.
* The main form and any support dialogs are created.
* An initial size is given, and the gui placed in the middle of the screen
*
* @param args the command line arguments
*
*/
public static void main(String args[]) {
try {
CommandLine cmdline = new CommandLine(args);
if (cmdline.exists("help")) {
// print the usage information
usage();
} else if (cmdline.exists("config")) {
ConfigurationManager.setConfig(cmdline.value("config"));
Configuration config = ConfigurationManager.getConfig();
AdminMgr admin = new AdminMgr();
QueryDialog.create(admin);
ObjectDialog.create(admin);
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
// About center of screen
admin.setLocation(screen.width / 2 - 150, screen.height / 2 - 150);
admin.setSize(300, 300);
admin.invalidate();
admin.show();
} else {
// anything else print the usage message
usage();
}
} catch (Exception err) {
err.printStackTrace();
System.err.println("Failed to initialize JNDI AdminMgr.\nExiting....");
}
}
/**
* Print out information on running this sevice
*/
static protected void usage() {
PrintStream out = System.out;
out.println("\n\n");
out.println("=====================================================");
out.println("Usage information for org.exolab.jms." +
"jndiadministration.AdminMgr");
out.println("=====================================================");
out.println("\norg.exolab.jms.jndiadministration.AdminMgr");
out.println(" [-help | -config <xml config file>]\n");
out.println("\t-help displays this screen\n");
out.println("\t-config file name of xml-based config file\n");
}
} // End AdminMgr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -