Skip to content
Snippets Groups Projects
Commit a5c862dc authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

- Use HistoryView (LogViewer) instead of deprecated HistoricView (SCAN-821)

- Prefer using constants to new strings
parent 0c9aee33
Branches
Tags
No related merge requests found
......@@ -63,7 +63,7 @@ import net.infonode.util.Direction;
public class ApplicationView extends JFrame implements IView<ApplicationController> {
/** Serialization id */
private static final long serialVersionUID = 3879501270323105123L;
private static final long serialVersionUID = 6280073476684137709L;
/** The logger for messages */
public static final Logger LOGGER = LoggingUtil.getLogger(ApplicationView.class);
......@@ -326,6 +326,8 @@ public class ApplicationView extends JFrame implements IView<ApplicationControll
private ConfigurationManagerBean configurationManagerBean;
private HistoryView historyView;
/** The model from preference @see DevicePreferences */
private transient DevicePreferences devicePreferences;
......@@ -779,9 +781,8 @@ public class ApplicationView extends JFrame implements IView<ApplicationControll
private View getHistoricDocking() {
if (historicDocking == null) {
notifySalsaSplash(SCAN_HISTORIC_VIEW);
HistoricView historicView = new HistoricView();
historicDocking = new View(SCAN_HISTORIC_VIEW, IconsHistoric.getIconHistoric("salsa.scanserver.history"),
historicView);
getHistoryView());
}
return historicDocking;
}
......@@ -934,6 +935,13 @@ public class ApplicationView extends JFrame implements IView<ApplicationControll
return configurationManagerBean;
}
public HistoryView getHistoryView() {
if (historyView == null) {
historyView = new HistoryView();
}
return historyView;
}
/**
* Refresh UI preference values from views before to save them
*/
......@@ -1547,6 +1555,8 @@ public class ApplicationView extends JFrame implements IView<ApplicationControll
public void setDevicePreferences(DevicePreferences devicePreferences) {
this.devicePreferences = devicePreferences;
stateChanged(new DevicePreferencesEvent(devicePreferences, DevicePreferencesEvent.Type.LOADING));
getHistoryView().setModel(devicePreferences == null ? null : devicePreferences.getScanServer());
getHistoryView().start();
getMenuBarViewTool().setDevicePreferences(devicePreferences);
}
......
......@@ -14,9 +14,11 @@ import javax.swing.table.DefaultTableCellRenderer;
* doesn't display which cell has the focus, - also, it displays the content of the cell in a
* tooltip, - rows with type "ERROR" are displayed in red.
*/
@Deprecated
public class HistoricTableCellRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = -8291018729074231746L;
private static final long serialVersionUID = -3413390432924319931L;
private final JLabel errorComponent = new JLabel();
public HistoricTableCellRenderer() {
......@@ -24,18 +26,17 @@ public class HistoricTableCellRenderer extends DefaultTableCellRenderer {
}
@Override
public Component getTableCellRendererComponent(JTable jTable, Object value, boolean isSelected,
boolean hasFocus, int row, int col) {
JComponent component = (JComponent) super.getTableCellRendererComponent(jTable, value,
isSelected, hasFocus, row, col);
public Component getTableCellRendererComponent(JTable jTable, Object value, boolean isSelected, boolean hasFocus,
int row, int col) {
JComponent component = (JComponent) super.getTableCellRendererComponent(jTable, value, isSelected, hasFocus,
row, col);
// Find ERROR label in line
boolean errorFound = false;
int nbOfColumn = jTable.getColumnCount();
for (int i = 0; i < nbOfColumn; i++) {
Object object = jTable.getValueAt(row, i);
if (object != null
&& (object.toString().equals("ERROR") || object.toString().equals("FATAL"))) {
if (object != null && (object.toString().equals("ERROR") || object.toString().equals("FATAL"))) {
errorFound = true;
break;
}
......@@ -44,14 +45,12 @@ public class HistoricTableCellRenderer extends DefaultTableCellRenderer {
if (errorFound) {
if (isSelected) {
component.setBackground(Color.RED);
}
else {
} else {
errorComponent.setText(value.toString());
errorComponent.setBackground(Color.ORANGE);
if (col == 2) {
errorComponent.setHorizontalAlignment(SwingConstants.LEFT);
}
else {
} else {
errorComponent.setHorizontalAlignment(SwingConstants.CENTER);
}
errorComponent.setOpaque(true);
......
......@@ -27,10 +27,13 @@ import fr.soleil.salsa.preferences.DevicePreferences;
/**
* Historic view. Shows the events of a scan.
*
* @deprecated Use {@link HistoryView} instead
*/
@Deprecated
public class HistoricView extends JPanel implements IScanServerListener {
private static final long serialVersionUID = -2651382670906967354L;
private static final long serialVersionUID = -4601029610076553719L;
public static final Logger LOGGER = LoggingUtil.getLogger(HistoricView.class);
......@@ -118,8 +121,7 @@ public class HistoricView extends JPanel implements IScanServerListener {
public void actionPerformed(ActionEvent e) {
try {
ScanApi.clearHistoric(scanServerName);
}
catch (SalsaDeviceException e1) {
} catch (SalsaDeviceException e1) {
LOGGER.error(e1.getMessage());
LOGGER.debug("Stack trace", e1);
}
......@@ -174,8 +176,7 @@ public class HistoricView extends JPanel implements IScanServerListener {
historicAsArray[index][2] = record.getMessage();
}
SwingUtilities.invokeLater(new UpdateDisplayTask(historicAsArray));
}
catch (SalsaDeviceException e) {
} catch (SalsaDeviceException e) {
LOGGER.warn(e.getMessage());
LOGGER.debug("Stack trace", e);
}
......
package fr.soleil.salsa.client.view;
import java.awt.BorderLayout;
import java.util.prefs.Preferences;
import fr.soleil.comete.box.AbstractTangoBox;
import fr.soleil.comete.box.matrixbox.StringMatrixBox;
import fr.soleil.comete.box.target.ADeviceLogAdapter;
import fr.soleil.comete.box.util.DeviceLogViewer;
import fr.soleil.comete.tango.data.service.TangoKey;
import fr.soleil.comete.tango.data.service.TangoKeyTool;
import fr.soleil.model.scanserver.CurrentScanDataModel;
/**
* Historic view. Shows the events of a scan.
*
* @author GIRARDOT
*/
public class HistoryView extends AbstractTangoBox {
private static final long serialVersionUID = -4719279750511116975L;
private static final String CLEAR_HISTORIC = "ClearHistoric";
private static final String CLEAR_HISTORIC_TITLE = "Clear Historic";
protected final DeviceLogViewer historyViewer;
protected ADeviceLogAdapter<?> logAdapter;
protected final StringMatrixBox stringMatrixBox;
public HistoryView() {
super();
historyViewer = new DeviceLogViewer(getClass().getName());
historyViewer.getClearDeviceLogsButton().setToolTipText(CLEAR_HISTORIC_TITLE);
historyViewer.setDefaultClearLogsButtonVisible(false);
stringMatrixBox = new StringMatrixBox();
stringBox.setDefaultToolTipEnabled(false);
setLayout(new BorderLayout());
add(historyViewer, BorderLayout.CENTER);
}
/**
* Connection to log attribute
*/
protected void connectHistory() {
TangoKey key = generateAttributeKey(CurrentScanDataModel.HISTORIC);
logAdapter = getAndConnectBestDeviceLogAdapter(historyViewer, key, stringMatrixBox);
connectCommandClearHistory();
}
protected void disconnectHistory() {
stringMatrixBox.disconnectWidgetFromAll(logAdapter);
disconnectCommandClearHistory();
}
protected void connectCommandClearHistory() {
TangoKey key = new TangoKey();
TangoKeyTool.registerCommand(key, getModel(), CLEAR_HISTORIC);
connectClearDeviceLogsButton(historyViewer, key, stringBox, DEFAULT_MESSAGE_MANAGER);
}
protected void disconnectCommandClearHistory() {
stringBox.disconnectWidgetFromAll(historyViewer.getClearDeviceLogsButton());
}
@Override
protected void clearGUI() {
disconnectHistory();
}
@Override
protected void refreshGUI() {
disconnectHistory();
connectHistory();
}
@Override
protected void onConnectionError() {
// not managed
}
@Override
protected void savePreferences(Preferences preferences) {
// not yet managed
}
@Override
protected void loadPreferences(Preferences preferences) {
// not yet managed
}
}
......@@ -5,6 +5,7 @@ import java.io.Serializable;
/**
* Event in the historic.
*/
@Deprecated
public class HistoricEvent implements Serializable {
private static final long serialVersionUID = -309440118958388542L;
......
......@@ -11,6 +11,7 @@ import javax.swing.table.TableModel;
*
* @see TableModel
*/
@Deprecated
public class HistoricEventTableModel extends AbstractTableModel {
private static final long serialVersionUID = 4937669864951919510L;
......@@ -77,6 +78,7 @@ public class HistoricEventTableModel extends AbstractTableModel {
/**
* Return the name of the column #columnIndex (starting at 0).
*/
@Override
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
......
......@@ -3,22 +3,28 @@ package fr.soleil.salsa.logging;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.soleil.lib.project.ObjectUtils;
import fr.soleil.lib.project.SystemUtils;
public class LoggingUtil {
private static final String HOME = "HOME";
private static final String SALSA_PERSPECTIVES_DIRECTORY = "SALSA_PERSPECTIVES_DIRECTORY";
private static final String USER_DIR = "user.dir";
private static final String USER_HOME = "user.home";
public static Logger getLogger(Class<?> clazz) {
// This should not be done in a getLogger method...
String homeProp = SystemUtils.getSystemProperty("HOME");
String homeProp = SystemUtils.getSystemProperty(HOME);
if ((homeProp == null) || homeProp.isEmpty()) {
String salsaPerspectiveDir = SystemUtils.getSystemProperty("SALSA_PERSPECTIVES_DIRECTORY");
String salsaPerspectiveDir = SystemUtils.getSystemProperty(SALSA_PERSPECTIVES_DIRECTORY);
if (salsaPerspectiveDir == null) {
salsaPerspectiveDir = System.getProperty("user.dir");
salsaPerspectiveDir = System.getProperty(USER_DIR);
}
if (salsaPerspectiveDir == null) {
salsaPerspectiveDir = System.getProperty("user.home", "");
salsaPerspectiveDir = System.getProperty(USER_HOME, ObjectUtils.EMPTY_STRING);
}
System.setProperty("HOME", salsaPerspectiveDir);
System.setProperty(HOME, salsaPerspectiveDir);
}
return LoggerFactory.getLogger(clazz);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment