/***************************************************
*
* cismet GmbH, Saarbruecken, Germany
*
* ... and it just works.
*
****************************************************/
package de.cismet.cids.custom.switchon.objectrenderer;
import Sirius.navigator.connection.SessionManager;
import Sirius.navigator.exception.ConnectionException;
import Sirius.server.middleware.types.MetaObject;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import de.cismet.cids.dynamics.CidsBean;
import de.cismet.cids.dynamics.CidsBeanStore;
import de.cismet.cids.dynamics.Disposable;
/**
* The RepresentationUploadFinishedPanel is a jPanel which checks the updateStatus of a representation. If the
* representation is still uploading, this is shown. If the upload is finished, it is shown if the upload was successful
* or not.
*
* @author Gilles Baatz
* @version $Revision$, $Date$
*/
public class RepresentationUploadFinishedPanel extends javax.swing.JPanel implements CidsBeanStore, Disposable {
//~ Static fields/initializers ---------------------------------------------
private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(
RepresentationUploadFinishedPanel.class);
//~ Instance fields --------------------------------------------------------
private final Timer timer;
private CidsBean representation;
// Variables declaration - do not modify//GEN-BEGIN:variables
private org.jdesktop.swingx.JXBusyLabel lblUpload;
// End of variables declaration//GEN-END:variables
//~ Constructors -----------------------------------------------------------
/**
* Creates new form RepresentationUploadFinishedPanel.
*/
public RepresentationUploadFinishedPanel() {
initComponents();
timer = new Timer(5000, new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final MetaObject mo;
CidsBean newRep = null;
try {
mo = SessionManager.getConnection()
.getMetaObject(
SessionManager.getSession().getUser(),
representation.getPrimaryKeyValue(),
representation.getMetaObject().getMetaClass().getId(),
"SWITCHON");
newRep = mo.getBean();
} catch (ConnectionException ex) {
LOG.error(ex, ex);
}
if (newRep != null) {
final CidsBean fiNewRep = newRep;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
representation = fiNewRep;
setLabelText();
}
});
}
}
});
timer.setRepeats(true);
}
//~ Methods ----------------------------------------------------------------
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
* content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
lblUpload = new org.jdesktop.swingx.JXBusyLabel();
setLayout(new java.awt.BorderLayout());
org.openide.awt.Mnemonics.setLocalizedText(
lblUpload,
org.openide.util.NbBundle.getMessage(
RepresentationUploadFinishedPanel.class,
"RepresentationUploadFinishedPanel.lblUpload.text")); // NOI18N
add(lblUpload, java.awt.BorderLayout.CENTER);
} // </editor-fold>//GEN-END:initComponents
@Override
public CidsBean getCidsBean() {
return representation;
}
@Override
public void setCidsBean(final CidsBean cidsBean) {
if (cidsBean != null) {
representation = cidsBean;
timer.start();
setLabelText();
}
}
/**
* DOCUMENT ME!
*/
private void setLabelText() {
if (representation != null) {
final CidsBean uploadStatus = (CidsBean)representation.getProperty("uploadstatus");
final String uploadMessage = (String)representation.getProperty("uploadmessage");
if (uploadStatus != null) {
lblUpload.setVisible(true);
final String status = (String)uploadStatus.getProperty("name");
lblUpload.setToolTipText(uploadMessage);
switch (status) {
case "uploading": {
lblUpload.setText("Uploading");
lblUpload.setBusy(true);
break;
}
case "finished": {
lblUpload.setText("Finished");
lblUpload.setBusy(false);
timer.stop();
break;
}
case "failed": {
lblUpload.setText("Failed");
lblUpload.setBusy(false);
timer.stop();
break;
}
}
} else {
lblUpload.setVisible(false);
timer.stop();
}
}
}
@Override
public void dispose() {
timer.stop();
}
}