initialize
This commit is contained in:
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
* Copyright (c) 2008 iTAC Software AG, Germany. All Rights Reserved.
|
||||
*
|
||||
* This software is protected by copyright. Under no circumstances may any part of this file in any form be copied, printed, edited
|
||||
* or otherwise distributed, be stored in a retrieval system, or be translated into another language without the written permission
|
||||
* of iTAC Software AG.
|
||||
*/
|
||||
package com.itac.mes.datainterface;
|
||||
|
||||
import static com.itac.artes.ArtesPropertyNames.PROP_ARTES_CLUSTERNODES;
|
||||
import static com.itac.util.PropertyNames.PROP_ITAC_APPID;
|
||||
import static com.itac.util.logging.LogLevel.ERROR;
|
||||
import static com.itac.util.logging.LogLevel.FATAL;
|
||||
import static com.itac.util.logging.LogLevel.INFO;
|
||||
import static com.itac.util.logging.LogLevel.WARN;
|
||||
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.jnlp.BasicService;
|
||||
import javax.jnlp.ServiceManager;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.itac.artes.ihas.LookupException;
|
||||
import com.itac.mes.datainterface.annotations.AInstantiationType;
|
||||
import com.itac.mes.datainterface.annotations.InstantiationType;
|
||||
import com.itac.mes.datainterface.data.Toolbox;
|
||||
import com.itac.mes.datainterface.factories.AConfigurableHandler;
|
||||
import com.itac.mes.datainterface.factories.CommonFactory;
|
||||
import com.itac.mes.datainterface.factories.FactoryException;
|
||||
import com.itac.mes.datainterface.factories.WorkerPaneFactory;
|
||||
import com.itac.mes.datainterface.gui.DIMAPropertyChangeListener;
|
||||
import com.itac.mes.datainterface.gui.DataInterfaceDlg;
|
||||
import com.itac.mes.datainterface.gui.DataInterfaceMenuAction;
|
||||
import com.itac.mes.datainterface.gui.IMainDlg;
|
||||
import com.itac.mes.datainterface.gui.IWorkerPane;
|
||||
import com.itac.mes.datainterface.service.DataInterfaceServices;
|
||||
import com.itac.mes.datainterface.work.Simulation;
|
||||
import com.itac.mes.datainterface.work.Worker;
|
||||
import com.itac.resource.ResourcePool;
|
||||
import com.itac.resource.ResourcesIMSInterfaces;
|
||||
import com.itac.resource.ResourcesInterfaceFramework;
|
||||
import com.itac.util.logging.LogHandler;
|
||||
|
||||
/**
|
||||
* Das ist die Hauptklasse des DataInterface. Das DataInterface bietet die Moeglichkeit ueber einen Plugin-Mechanismus
|
||||
* verschiedenste Auspraegungen eine Interface zu instantiieren.
|
||||
*
|
||||
* @author frankp
|
||||
*/
|
||||
@AInstantiationType(name = "client", type = InstantiationType.TOOL)
|
||||
public class DataInterfaceWithGui extends DataInterfaceClient implements DIMAPropertyChangeListener {
|
||||
|
||||
public static final String APPTYPE = "DataInterface";
|
||||
public static DataInterfaceWithGui dataInterface;
|
||||
private Worker worker;
|
||||
// Maschinen Simulationen werden hiervon gemanaged
|
||||
private Simulation simulation;
|
||||
private IMainDlg dataInterfaceDlg;
|
||||
private WindowSettings windowSettings;
|
||||
// it's required to have those parameters here to create them automatically on starting as webstart appliation
|
||||
private RemoteLocation remoteLocation;
|
||||
private CommonFactory<AConfigurableHandler> factory;
|
||||
|
||||
/**
|
||||
* @param factory
|
||||
* @param args
|
||||
*/
|
||||
public DataInterfaceWithGui(CommonFactory<AConfigurableHandler> factory, String[] args) {
|
||||
super();
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (System.getProperty(PROP_ARTES_CLUSTERNODES) == null) {
|
||||
try {
|
||||
BasicService bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
|
||||
URL url = bs.getCodeBase();
|
||||
// die folgende Erkennung muss bei "normalen" und "custom" Interface funktionieren
|
||||
// http://localhost:8080/imsinterfaces/webstart
|
||||
// http://localhost:8080/imsinterfaces-customer/webstart
|
||||
// url parsing unterschiedlich
|
||||
URL newUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), "/mes");
|
||||
String value = newUrl.toString();
|
||||
System.out.println("autodetect: set property " + PROP_ARTES_CLUSTERNODES + " to " + value);
|
||||
System.setProperty(PROP_ARTES_CLUSTERNODES, value);
|
||||
} catch (Exception ex) {
|
||||
LogHandler.log(APPTYPE, ERROR, "automatic detection of MES failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception cnfe) {
|
||||
// keep System err and printStackTrace, because at the moment of calling logging is not initialized
|
||||
System.err.println("Failed to set LookAndFeel");
|
||||
cnfe.printStackTrace();
|
||||
}
|
||||
try {
|
||||
|
||||
// create the compontnFactory
|
||||
CommonFactory<AConfigurableHandler> factory = new CommonFactory<AConfigurableHandler>();
|
||||
|
||||
// check access to imsServices
|
||||
DataInterfaceServices services = (DataInterfaceServices) factory.get(DataInterfaceServices.class, "");
|
||||
// access to imsApi granted
|
||||
|
||||
// special case: create and set DataInterfaceConfig explicit; this is not an instance of AConfigurableHandler
|
||||
DataInterfaceConfiguration configuration = new DataInterfaceConfiguration(services);
|
||||
factory.setDataInterfaceConfiguration(configuration);
|
||||
factory.callAtInit();
|
||||
|
||||
DataInterfaceWithGui.dataInterface = new DataInterfaceWithGui(factory, args);
|
||||
DataInterfaceWithGui.dataInterface.start();
|
||||
} catch (ConfigurationUpdateException ex) {
|
||||
JOptionPane.showMessageDialog(null, ResourcePool.getInstance().getString(ResourcesIMSInterfaces.UPDATE_PARAMETER), APPTYPE,
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
System.exit(0);
|
||||
} catch (LookupException ex) {
|
||||
LogHandler.log(APPTYPE, ERROR, "lookup failed", ex);
|
||||
DataInterfaceWithGui.dataInterface.finish();
|
||||
} catch (ConfigurationException ex) {
|
||||
LogHandler.log(APPTYPE, ERROR, "Loading configuration failed", ex);
|
||||
JOptionPane.showMessageDialog(null, ex.getMessage(), APPTYPE, JOptionPane.INFORMATION_MESSAGE);
|
||||
System.exit(0);
|
||||
} catch (FactoryException ex) {
|
||||
LogHandler.log(APPTYPE, ERROR, "Factory Exception", ex);
|
||||
DataInterface.dataInterface.finish();
|
||||
} catch (Exception e) {
|
||||
LogHandler.log(APPTYPE, ERROR, "Exception", e);
|
||||
DataInterface.dataInterface.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws FactoryException, ConfigurationException {
|
||||
// implizites erzeugen aller Dienste etc.
|
||||
super.start();
|
||||
|
||||
Toolbox toolbox = (Toolbox) factory.deepCreate(Toolbox.class.getName(), "");
|
||||
// jetzt muessen alle annotierten Elemente in der Toolbox erzeugt worden sein.
|
||||
if (toolbox.getConfigurationResult() != OK) {
|
||||
writeMessage(ERROR, toolbox.getConfigurationText());
|
||||
}
|
||||
|
||||
// put the own (full qualified, z.B. itacpc333.itac.intra to the configuration
|
||||
// in combination with the configured port the DataInterfaceAdminconsole can
|
||||
// remote connect to this instance
|
||||
remoteLocation = (RemoteLocation) factory.deepCreate(RemoteLocation.class.getName(), "");
|
||||
if (remoteLocation.getConfigurationResult() != AConfigurableHandler.OK) {
|
||||
writeMessage(ERROR, remoteLocation.getConfigurationText());
|
||||
}
|
||||
remoteLocation.updateHostname();
|
||||
|
||||
windowSettings = (WindowSettings) factory.deepCreate(WindowSettings.class.getName(), "");
|
||||
if (windowSettings.getConfigurationResult() != OK) {
|
||||
writeMessage(ERROR, windowSettings.getConfigurationText());
|
||||
}
|
||||
|
||||
dataInterfaceDlg = new DataInterfaceDlg();
|
||||
|
||||
if (dataInterfaceDlg instanceof DataInterfaceDlg) {
|
||||
// Operation, die nur auf einem JFrame funktioniert
|
||||
|
||||
((JFrame) dataInterfaceDlg).addWindowListener(new WindowAdapter() {
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
((DataInterfaceDlg) dataInterfaceDlg).getMniExit().setAction(
|
||||
new AbstractAction(ResourcePool.getInstance().getString(ResourcesInterfaceFramework.INTERFACEFRAMEWORK_MENU_EXIT)) {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
// window Position and size
|
||||
initDialog();
|
||||
}
|
||||
|
||||
WorkerPaneFactory wpf = new WorkerPaneFactory(WorkerPaneFactory.MODE.WITH_GUI);
|
||||
IWorkerPane interfaceMainPane = wpf.getOrCreateWorkerPane(DataInterfaceDlg.INTERFACE_TAB_NAME);
|
||||
|
||||
// IWorkerPane interfaceMainPane = dataInterfaceDlg.getOrCreateWorkerPane(DataInterfaceDlg.INTERFACE_TAB_NAME);
|
||||
dataInterfaceDlg.setMainPaneName(DataInterfaceDlg.INTERFACE_TAB_NAME);
|
||||
|
||||
// alle einzel lauffaehige Instanzen
|
||||
worker = (Worker) factory.deepCreate(Worker.class.getName(), "");
|
||||
if (worker.getConfigurationResult() != AConfigurableHandler.OK) {
|
||||
writeMessage(ERROR, worker.getConfigurationText());
|
||||
}
|
||||
|
||||
worker.setWorkerPaneFactory(wpf);
|
||||
dataInterfaceDlg.setWorker(worker);
|
||||
dataInterfaceDlg.createWorkerView(interfaceMainPane, null);
|
||||
|
||||
factory.addMessageListener(interfaceMainPane);
|
||||
|
||||
worker.addMessageListener(interfaceMainPane);
|
||||
worker.setDIMAPropertyChangeListener(this);
|
||||
worker.initialize(dataInterfaceDlg, interfaceMainPane, factory);
|
||||
|
||||
toolbox.setWorkerInstances(worker.getInstances());
|
||||
|
||||
String mainPaneName = DataInterfaceDlg.INTERFACE_TAB_NAME + ", appid=" + System.getProperty(PROP_ITAC_APPID);
|
||||
interfaceMainPane.setDescription(mainPaneName);
|
||||
|
||||
// alle Instanzen, die zu einer Simulation gehoeren
|
||||
simulation = (Simulation) factory.deepCreate(Simulation.class.getName(), "");
|
||||
|
||||
dataInterfaceDlg.setSimulation(simulation);
|
||||
simulation.initialize(dataInterfaceDlg, interfaceMainPane, factory);
|
||||
|
||||
if (toolbox.getConfigurationResult() != OK) {
|
||||
worker.initFailure(toolbox.getConfigurationText());
|
||||
}
|
||||
|
||||
if (worker.getState() == WARN || worker.getState() == ERROR || worker.getState() == FATAL) {
|
||||
// 1 tab anzeigen
|
||||
dataInterfaceDlg.initFailure();
|
||||
} else {
|
||||
worker.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
try {
|
||||
((DataInterfaceServices) factory.get(DataInterfaceServices.class, "")).logout();
|
||||
} catch (FactoryException e) {
|
||||
LogHandler.log(APPTYPE, ERROR, "Logout failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void finish() {
|
||||
try {
|
||||
worker.finish();
|
||||
} catch (Throwable th) {
|
||||
LogHandler.log(APPTYPE, ERROR, "finish failed", th);
|
||||
}
|
||||
if (dataInterfaceDlg instanceof DataInterfaceDlg) {
|
||||
// Operation, die nur auf einem JFrame funktioniert
|
||||
windowSettings.setExtents(((JFrame) dataInterfaceDlg).getBounds());
|
||||
windowSettings.setExtendedState(((JFrame) dataInterfaceDlg).getExtendedState());
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
private void initDialog() {
|
||||
Rectangle extents = windowSettings.getExtents();
|
||||
Point position = new Point(extents.x, extents.y);
|
||||
GraphicsConfiguration gc = null;
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] gd = ge.getScreenDevices();
|
||||
for (GraphicsDevice element : gd) {
|
||||
if (element.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
|
||||
GraphicsConfiguration dgc = element.getDefaultConfiguration();
|
||||
Rectangle bounds = dgc.getBounds();
|
||||
if (bounds.contains(position)) {
|
||||
gc = dgc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gc == null) {
|
||||
LogHandler.log(APPTYPE, INFO, "setting windows top left position to 0,0");
|
||||
position.x = 0;
|
||||
position.y = 0;
|
||||
}
|
||||
if (dataInterfaceDlg instanceof DataInterfaceDlg) {
|
||||
// Operation, die nur auf einem JFrame funktioniert
|
||||
dataInterfaceDlg.setTitle(windowSettings.getTitle());
|
||||
((JFrame) dataInterfaceDlg).setLocation(position.x, position.y);
|
||||
if (extents.width != 0 && extents.height != 0) {
|
||||
((JFrame) dataInterfaceDlg).setSize(extents.width, extents.height);
|
||||
}
|
||||
}
|
||||
dataInterfaceDlg.setVisible(true);
|
||||
((JFrame) dataInterfaceDlg).setExtendedState(windowSettings.getExtendedState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertiesChanged(DataInterfaceMenuAction menuAction) {
|
||||
// delegate changed properties
|
||||
try {
|
||||
if (worker != null) {
|
||||
worker.notifyActionPropertiesChanged(menuAction.getInstanceName(), menuAction);
|
||||
}
|
||||
if (simulation != null) {
|
||||
simulation.notifyActionPropertiesChanged(menuAction.getInstanceName(), menuAction);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2013 iTAC Software AG, Germany. All Rights Reserved.
|
||||
*
|
||||
* This software is protected by copyright. Under no circumstances may any part of this file in any form be copied,
|
||||
* printed, edited or otherwise distributed, be stored in a retrieval system, or be translated into another language
|
||||
* without the written permission of iTAC Software AG.
|
||||
*/
|
||||
package com.itac.mes.datainterface;
|
||||
|
||||
import static com.itac.mes.datainterface.ParameterUpdateTool.DEFAULT_DIM_PATH;
|
||||
import static com.itac.mes.datainterface.ParameterUpdateTool.HANDLER_DIM_PATH;
|
||||
import static com.itac.util.logging.LogLevel.ERROR;
|
||||
import static com.itac.util.logging.LogLevel.INFO;
|
||||
|
||||
import java.awt.Frame;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import com.itac.mes.config.domain.Parameter;
|
||||
import com.itac.mes.datainterface.annotations.AInstantiationType;
|
||||
import com.itac.mes.datainterface.annotations.AParamValue;
|
||||
import com.itac.mes.datainterface.annotations.AParameter;
|
||||
import com.itac.mes.datainterface.annotations.AParameterDefaultValue;
|
||||
import com.itac.mes.datainterface.annotations.InstantiationType;
|
||||
import com.itac.mes.datainterface.factories.AConfigurableHandler;
|
||||
import com.itac.util.logging.LogHandler;
|
||||
|
||||
/**
|
||||
* Zugriff auf Fenstereinstellungen, Titel, Positionen etc.
|
||||
*
|
||||
* @author frankp
|
||||
* @since 17.04.2013
|
||||
*/
|
||||
@AInstantiationType(name = "windowsettings", type = InstantiationType.TOOL, createRootParameter = true, singleton = true)
|
||||
public class WindowSettings extends AConfigurableHandler {
|
||||
|
||||
private static final String LOGGER = WindowSettings.class.getSimpleName();
|
||||
public static final String WINDOW = "window";
|
||||
public static final String TITLE = WINDOW + ".title";
|
||||
public static final String POSITION = WINDOW + ".position";
|
||||
public static final String WINDOW_POSITION = WINDOW + ".windowPosition";
|
||||
public static final String STATE = WINDOW + ".extendedState";
|
||||
|
||||
@AParameter(name = WINDOW, description = "window settings", dimPath = DEFAULT_DIM_PATH, ordering = "2050")
|
||||
private Parameter paramRoot;
|
||||
@AParameter(name = TITLE, parent = WINDOW, description = "window title", type = String.class, dimPath = DEFAULT_DIM_PATH)
|
||||
private Parameter paramTitle;
|
||||
@AParameter(name = POSITION, parent = WINDOW, description = "window position", type = java.awt.Rectangle.class,
|
||||
dimPath = HANDLER_DIM_PATH)
|
||||
private Parameter paramPosition;
|
||||
@AParameter(name = STATE, parent = WINDOW, description = "extended window state", type = String.class, dimPath = DEFAULT_DIM_PATH)
|
||||
private Parameter paramWindowState;
|
||||
|
||||
@AParameterDefaultValue(name = STATE)
|
||||
private String state = "normal";
|
||||
|
||||
@AParamValue(value = TITLE)
|
||||
private String title;
|
||||
@AParamValue(value = POSITION, allowEmpty = true)
|
||||
private java.awt.Rectangle extents = new java.awt.Rectangle(0, 0, 600, 400);
|
||||
private int extendedState = 0;
|
||||
|
||||
@AParamValue(value = STATE, allowEmpty = true)
|
||||
protected void setState(String state) {
|
||||
extendedState = getExtendedState(state);
|
||||
}
|
||||
|
||||
private int getExtendedState(String sExtendedString) {
|
||||
extendedState = 0;
|
||||
if (sExtendedString.contains("normal")) {
|
||||
extendedState = extendedState | JFrame.NORMAL;
|
||||
}
|
||||
if (sExtendedString.contains("iconified")) {
|
||||
extendedState = extendedState | JFrame.ICONIFIED;
|
||||
}
|
||||
if (sExtendedString.contains("maximized")) {
|
||||
extendedState = extendedState | JFrame.MAXIMIZED_BOTH;
|
||||
}
|
||||
if (sExtendedString.contains("maximized_horiz")) {
|
||||
extendedState = extendedState | JFrame.MAXIMIZED_HORIZ;
|
||||
}
|
||||
if (sExtendedString.contains("maximized_vert")) {
|
||||
extendedState = extendedState | JFrame.MAXIMIZED_VERT;
|
||||
}
|
||||
return extendedState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return der gespeicherte Title fuer diesen Dialog
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title == null ? "" : title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return die gespeicherte Fensterpositionen fuer diesen Dialog
|
||||
*/
|
||||
public java.awt.Rectangle getExtents() {
|
||||
return extents;
|
||||
}
|
||||
|
||||
public int getExtendedState() {
|
||||
return JFrame.NORMAL;
|
||||
}
|
||||
|
||||
public void setExtendedState(int iExtendedState) {
|
||||
// aus dem extended State einen String machen, diesen speichern
|
||||
LogHandler.log(LOGGER, INFO, "updating window state");
|
||||
String extString = "";
|
||||
if (iExtendedState == Frame.NORMAL) {
|
||||
extString = "normal";
|
||||
} else {
|
||||
if ((iExtendedState & Frame.ICONIFIED) != 0) {
|
||||
extString = "iconified";
|
||||
}
|
||||
if ((iExtendedState & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH) {
|
||||
extString = "maximized";
|
||||
} else if ((iExtendedState & Frame.MAXIMIZED_HORIZ) != 0) {
|
||||
extString = "maximized_horiz";
|
||||
} else if ((iExtendedState & Frame.MAXIMIZED_VERT) != 0) {
|
||||
extString = "maximized_vert";
|
||||
}
|
||||
}
|
||||
try {
|
||||
updateValue(STATE, extString);
|
||||
} catch (Exception e) {
|
||||
LogHandler.log(LOGGER, ERROR, "unable to update window state in configuration");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setting the extents automatically tries to store the extents as new position in configuration
|
||||
*
|
||||
* @param bounds
|
||||
*/
|
||||
public void setExtents(java.awt.Rectangle bounds) {
|
||||
LogHandler.log(LOGGER, INFO, "updating window position");
|
||||
try {
|
||||
updateValue(POSITION, bounds);
|
||||
} catch (Exception e) {
|
||||
LogHandler.log(LOGGER, ERROR, "unable to update window position in configuration");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# alle verfügbaren FileHandler
|
||||
com.itac.mes.datainterface.WindowSettings
|
||||
|
||||
Reference in New Issue
Block a user