use of javax.swing.SwingWorker in project ACS by ACS-Community.
the class TreeMouseListener method getLogConfFromContainer.
/**
* Get the LoggingConfigurable out of the container
*
* @return The LoggingConfigurable for the container
*/
private LoggingConfigurableOperations getLogConfFromContainer(ContainerInfo info) throws Exception {
if (info == null) {
throw new IllegalArgumentException("Invalid null ContainerInfo");
}
final Container cnt = info.reference;
if (cnt == null) {
throw new Exception("The reference to the container is null in ContainerInfo");
}
SwingWorker<LoggingConfigurableOperations, Void> worker = new SwingWorker<LoggingConfigurableOperations, Void>() {
protected LoggingConfigurableOperations doInBackground() throws Exception {
LoggingConfigurableOperations logConf;
try {
logConf = LoggingConfigurableHelper.narrow(cnt);
} catch (Throwable t) {
throw new Exception("Error getting the LoggingConfigurable out of Manager:\n" + t.getMessage(), t);
}
return logConf;
}
};
worker.execute();
return worker.get();
}
use of javax.swing.SwingWorker in project ACS by ACS-Community.
the class TreeMouseListener method getLogConfFromManager.
/**
* Get the LoggingConfigurable out of the manager
*
* @return The LoggingConfigurable for the manager
*/
private LoggingConfigurableOperations getLogConfFromManager() throws Exception {
System.out.println("Getting LoggingConfigurable out of Manager");
// Manager
Manager mgr = model.getManagerRef();
if (mgr == null) {
throw new Exception("Invalid manager reference");
}
SwingWorker<LoggingConfigurableOperations, Void> worker = new SwingWorker<LoggingConfigurableOperations, Void>() {
protected LoggingConfigurableOperations doInBackground() throws Exception {
LoggingConfigurableOperations logConf;
try {
logConf = LoggingConfigurableHelper.narrow(model.getManagerRef());
} catch (Throwable t) {
throw new Exception("Error getting the LoggingConfigurable out of Manager:\n" + t.getMessage(), t);
}
return logConf;
}
};
worker.execute();
return worker.get();
}
use of javax.swing.SwingWorker in project ACS by ACS-Community.
the class LogLevelFrame method connectACSComponentClient.
/**
* Connect to ACS as component client.
* It connects the client and the logger.
*
* @throws Exception In case of failure connecting to ACS
*/
private void connectACSComponentClient() throws Exception {
final String clientName = "LogLevel GUI";
final String managerLoc = (System.getProperty("ACS.manager") == null ? "" : System.getProperty("ACS.manager").trim());
if (managerLoc.equals(""))
throw new IllegalStateException("ACS.magager property not set!");
SwingWorker<ComponentClient, Void> worker = new SwingWorker<ComponentClient, Void>() {
protected ComponentClient doInBackground() throws Exception {
ComponentClient tmp;
try {
tmp = new ComponentClient(null, managerLoc, clientName);
} catch (Exception e) {
if (logger != null) {
logger.log(AcsLogLevel.ERROR, "Error connecting the simple client: " + e.getMessage());
} else {
System.err.println("Error connecting the simple client: " + e.getMessage());
}
client = null;
logger = null;
contSvc = null;
throw e;
}
return tmp;
}
};
worker.execute();
client = worker.get();
contSvc = client.getContainerServices();
logger = contSvc.getLogger();
logger.log(AcsLogLevel.INFO, "Connected to ACS");
}
use of javax.swing.SwingWorker in project ACS by ACS-Community.
the class ScriptFilter method getComponentComboBox.
/**
* This method initializes ComponentComboBox
* @return javax.swing.JComboBox
*/
private JComboBox getComponentComboBox() {
if (ComponentComboBox == null) {
ComponentComboBox = new JComboBox();
ComponentComboBox.setPreferredSize(new Dimension(320, 24));
//ComponentComboBox.setSize(ComponentComboBox.getPreferredSize());
ComponentComboBox.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
if (e.getStateChange() == java.awt.event.ItemEvent.DESELECTED)
return;
PropertyComboBox.setEnabled(true);
String comp = e.getItem().toString();
PropertyComboBox.removeAllItems();
for (int i = 0; i < compList.length; i++) {
/* We find the component. We show the properties for it. If we do not
* have them, we go and find them */
if (compList[i].compareTo(comp) == 0) {
if (propList.get(i) == null) {
/* If we can't get the list of properties for the interface,
* (cuased because of the IR not available or not
* having the interface definition), this should be
* notified to the user. */
final int k = i;
SwingWorker<List<String>, Object> sw = new SwingWorker<List<String>, Object>() {
public List<String> doInBackground() {
ComponentComboBox.setEnabled(false);
PropertyComboBox.setEnabled(false);
List<String> list_ = SampTool.getPropsForComponent(compList[k]);
return list_;
}
public void done() {
ComponentComboBox.setEnabled(true);
PropertyComboBox.setEnabled(true);
}
};
sw.execute();
try {
List<String> list = sw.get();
if (list == null) {
PropertyComboBox.removeAllItems();
PropertyComboBox.setEnabled(false);
ComponentComboBox.hidePopup();
JOptionPane.showMessageDialog(PropertyComboBox.getParent().getParent(), "The interface definition for the component '" + comp + "' could not be found in the Interface Repository\n" + "Please check that you have the Interface Repository running " + "and that the interface is loaded into it", "IR error", JOptionPane.ERROR_MESSAGE);
} else {
propList.add(i, list);
}
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ExecutionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
if (propList.get(i) != null) {
fillPropertyComboBox(propList.get(i));
}
} catch (IndexOutOfBoundsException ex) {
PropertyComboBox.removeAllItems();
PropertyComboBox.setEnabled(false);
} catch (Exception e1) {
System.out.println("Unknow exception " + e1);
}
}
}
if (PropertyComboBox.getItemCount() == 0)
addSampleButton.setEnabled(false);
else
addSampleButton.setEnabled(true);
}
});
}
return ComponentComboBox;
}
use of javax.swing.SwingWorker in project jdk8u_jdk by JetBrains.
the class XSheet method displayMetadataNode.
// Call on EDT
private void displayMetadataNode(final DefaultMutableTreeNode node) {
final XNodeInfo uo = (XNodeInfo) node.getUserObject();
final XMBeanInfo mbi = mbeanInfo;
switch(uo.getType()) {
case ATTRIBUTE:
SwingWorker<MBeanAttributeInfo, Void> sw = new SwingWorker<MBeanAttributeInfo, Void>() {
@Override
public MBeanAttributeInfo doInBackground() {
Object attrData = uo.getData();
mbean = (XMBean) ((Object[]) attrData)[0];
MBeanAttributeInfo mbai = (MBeanAttributeInfo) ((Object[]) attrData)[1];
mbeanAttributes.loadAttributes(mbean, new MBeanInfo(null, null, new MBeanAttributeInfo[] { mbai }, null, null, null));
return mbai;
}
@Override
protected void done() {
try {
MBeanAttributeInfo mbai = get();
if (!isSelectedNode(node, currentNode)) {
return;
}
invalidate();
mainPanel.removeAll();
JPanel attributePanel = new JPanel(new BorderLayout());
JPanel attributeBorderPanel = new JPanel(new BorderLayout());
attributeBorderPanel.setBorder(BorderFactory.createTitledBorder(Messages.ATTRIBUTE_VALUE));
JPanel attributeValuePanel = new JPanel(new BorderLayout());
attributeValuePanel.setBorder(LineBorder.createGrayLineBorder());
attributeValuePanel.add(mbeanAttributes.getTableHeader(), BorderLayout.PAGE_START);
attributeValuePanel.add(mbeanAttributes, BorderLayout.CENTER);
attributeBorderPanel.add(attributeValuePanel, BorderLayout.CENTER);
JPanel refreshButtonPanel = new JPanel();
refreshButtonPanel.add(refreshButton);
attributeBorderPanel.add(refreshButtonPanel, BorderLayout.SOUTH);
refreshButton.setEnabled(true);
attributePanel.add(attributeBorderPanel, BorderLayout.NORTH);
mbi.addMBeanAttributeInfo(mbai);
attributePanel.add(mbi, BorderLayout.CENTER);
mainPanel.add(attributePanel, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
} catch (Exception e) {
Throwable t = Utils.getActualException(e);
if (JConsole.isDebug()) {
System.err.println("Problem displaying MBean " + "attribute for MBean [" + mbean.getObjectName() + "]");
t.printStackTrace();
}
showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN);
}
}
};
sw.execute();
break;
case OPERATION:
Object operData = uo.getData();
mbean = (XMBean) ((Object[]) operData)[0];
MBeanOperationInfo mboi = (MBeanOperationInfo) ((Object[]) operData)[1];
mbeanOperations.loadOperations(mbean, new MBeanInfo(null, null, null, null, new MBeanOperationInfo[] { mboi }, null));
invalidate();
mainPanel.removeAll();
JPanel operationPanel = new JPanel(new BorderLayout());
JPanel operationBorderPanel = new JPanel(new BorderLayout());
operationBorderPanel.setBorder(BorderFactory.createTitledBorder(Messages.OPERATION_INVOCATION));
operationBorderPanel.add(new JScrollPane(mbeanOperations));
operationPanel.add(operationBorderPanel, BorderLayout.NORTH);
mbi.addMBeanOperationInfo(mboi);
operationPanel.add(mbi, BorderLayout.CENTER);
mainPanel.add(operationPanel, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
break;
case NOTIFICATION:
Object notifData = uo.getData();
invalidate();
mainPanel.removeAll();
mbi.addMBeanNotificationInfo((MBeanNotificationInfo) notifData);
mainPanel.add(mbi, BorderLayout.CENTER);
southPanel.setVisible(false);
southPanel.removeAll();
validate();
repaint();
break;
}
}
Aggregations