Search in sources :

Example 1 with Converter

use of si.ijs.acs.objectexplorer.engine.Converter in project ACS by ACS-Community.

the class ObjectExplorer method oETree1_MouseClicked.

/**
	 * Comment
	 */
public void oETree1_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
    //TODO ?!?!?!?!?!?!?
    if (SwingUtilities.isRightMouseButton(mouseEvent)) {
        TreePath clickedPath = getOETree1().getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
        Object clicked = null;
        if (clickedPath != null)
            clicked = clickedPath.getLastPathComponent();
        if (clicked instanceof Introspectable) {
            Introspectable node = (Introspectable) clicked;
            getconnectMenuItem().setEnabled(!node.isConnected());
            getdisconnectMenuItem().setEnabled(node.isConnected() && !node.isNonSticky());
            getJLabel1().setText(node.toString());
            getTreeHandlerBean1().setClicked(node);
            // disable/enable converters
            Converter currentConverter = ObjectExplorer.getConverter(node);
            int len = getconverterMenu().getItemCount();
            for (int i = 0; i < len; i++) {
                JMenuItem item = getconverterMenu().getItem(i);
                if (item != null && item.getActionListeners() != null && item.getActionListeners().length == 1 && item.getActionListeners()[0] instanceof SetConverterActionListener) {
                    SetConverterActionListener scal = (SetConverterActionListener) item.getActionListeners()[0];
                    if (scal.getConverter() == currentConverter)
                        item.setEnabled(false);
                    else
                        item.setEnabled(true);
                }
            }
            getoeTreePopup().show(getOETree1(), mouseEvent.getX(), mouseEvent.getY());
        }
    }
    return;
}
Also used : TreePath(javax.swing.tree.TreePath) SimpleIntrospectable(si.ijs.acs.objectexplorer.engine.SimpleIntrospectable) Introspectable(si.ijs.acs.objectexplorer.engine.Introspectable) Converter(si.ijs.acs.objectexplorer.engine.Converter) JMenuItem(javax.swing.JMenuItem)

Example 2 with Converter

use of si.ijs.acs.objectexplorer.engine.Converter in project ACS by ACS-Community.

the class ObjectExplorer method getconverterMenu.

/**
	 * Return the convertMenuItem property value.
	 * @return javax.swing.JMenuItem
	 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JMenu getconverterMenu() {
    if (ivjconverterMenu == null) {
        try {
            ivjconverterMenu = new javax.swing.JMenu();
            ivjconverterMenu.setName("converterMenu");
            ivjconverterMenu.setText("convert");
            // user code begin {1}
            // list of converters is static
            List converters = getConverterRepository();
            if (converters.size() > 0) {
                JMenuItem item = new JMenuItem("none");
                item.addActionListener(new SetConverterActionListener(null));
                ivjconverterMenu.add(item);
                ivjconverterMenu.add(new JSeparator());
            }
            Iterator iter = converters.iterator();
            while (iter.hasNext()) {
                Converter converter = (Converter) iter.next();
                JMenuItem item = new JMenuItem(converter.getDescription());
                item.addActionListener(new SetConverterActionListener(converter));
                ivjconverterMenu.add(item);
            }
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    return ivjconverterMenu;
}
Also used : Iterator(java.util.Iterator) JMenu(javax.swing.JMenu) Converter(si.ijs.acs.objectexplorer.engine.Converter) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem) JSeparator(javax.swing.JSeparator)

Example 3 with Converter

use of si.ijs.acs.objectexplorer.engine.Converter in project ACS by ACS-Community.

the class ReporterBean method toString.

/**
 */
public static String toString(RemoteCall call, boolean expand) {
    StringBuffer result = new StringBuffer(500);
    result.append('[');
    result.append(call.getSN());
    result.append("] : ");
    //result.append(System.currentTimeMillis());
    result.append(IsoDateFormat.formatCurrentDate());
    result.append(" |--------------------------------------------------------\n");
    result.append(call.getIntrospectable().getName());
    String name = null;
    if (call.getAttribute() == null) {
        if (call.getOperation() != null)
            name = call.getOperation().getName();
        else
            throw (new NullPointerException("RemoteCall -- both Operation and Attribute are null"));
    } else
        name = call.getAttribute().toString();
    // do the conversion
    Converter converter;
    if (call.isAttributeAccess())
        converter = ObjectExplorer.getConverter(call.getAttribute().getIntrospectable());
    else
        converter = ObjectExplorer.getConverter(call.getOperation().getIntrospectable());
    Object returnValue = call.getSyncReturnValue();
    Object[] auxs = call.getAuxReturnValues();
    if (converter != null && converter.acceptConvert(name))
        returnValue = converter.convert(name, auxs, returnValue);
    result.append('.');
    result.append(name);
    result.append('\n');
    result.append(" --> Return value: ");
    if ((call.getOperation() != null) && (call.getOperation().getReturnType().getType() == Void.TYPE))
        result.append("void");
    else {
        if (returnValue == null)
            result.append(DataFormatter.unpackReturnValue(returnValue, "      ", 0, expand));
        else if (returnValue.getClass().isArray())
            result.append(DataElementFormatter.unpackArray(returnValue, "      ", 0, expand));
        else if (returnValue instanceof DataElement)
            result.append(((DataElement) returnValue).toString("      ", 0, expand));
        else
            result.append(DataFormatter.unpackReturnValue(returnValue, "      ", 0, expand));
    }
    result.append('\n');
    if (auxs != null) {
        for (int i = 0; i < auxs.length; i++) if (auxs[i] != null) {
            if (auxs[i].getClass().isArray())
                result.append(" --> Auxiliary return value '" + call.getOperation().getParameterNames()[i] + "' = " + DataElementFormatter.unpackArray(auxs[i], "      ", 0, expand));
            else if (auxs[i] instanceof DataElement)
                result.append(" --> Auxiliary return value '" + call.getOperation().getParameterNames()[i] + "' = " + ((DataElement) auxs[i]).toString("      ", 0, expand) + "\n");
            else
                result.append(" --> Auxiliary return value '" + call.getOperation().getParameterNames()[i] + "' = " + DataFormatter.unpackReturnValue(auxs[i], "      ", 0, expand) + "\n");
        }
        result.append('\n');
    }
    if (call.getThrowable() != null) {
        result.append(" --> Exception: " + call.getThrowable() + "\n");
        if (call.getThrowable() instanceof DataElement)
            result.append(((DataElement) call.getThrowable()).toString("/      ", 0, expand));
        else
            result.append(DataFormatter.unpackReturnValue(call.getThrowable(), "/      ", 0, expand));
    }
    if (call.isTimeout()) {
        result.append(" --> Timeout raised by the engine while waiting for response.\n");
    }
    return result.toString();
}
Also used : DataElement(si.ijs.acs.objectexplorer.engine.DataElement) Converter(si.ijs.acs.objectexplorer.engine.Converter)

Example 4 with Converter

use of si.ijs.acs.objectexplorer.engine.Converter in project ACS by ACS-Community.

the class ObjectExplorer method oeTreeByName_MouseClicked.

//	----- * by rbertoncelj
//	----- Additional methods needed for new tree hierarchy -----
public void oeTreeByName_MouseClicked(java.awt.event.MouseEvent mouseEvent) {
    if (SwingUtilities.isRightMouseButton(mouseEvent)) {
        TreePath clickedPath = getOETreeByName().getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
        Object clicked = null;
        if (clickedPath != null)
            clicked = clickedPath.getLastPathComponent();
        if (clicked instanceof Introspectable) {
            Introspectable node = (Introspectable) clicked;
            getconnectMenuItem().setEnabled(!node.isConnected());
            getdisconnectMenuItem().setEnabled(node.isConnected());
            getJLabel1().setText(node.toString());
            //TODO is this ok?
            getTreeHandlerBean1().setClicked(node);
            // disable/enable converters
            Converter currentConverter = ObjectExplorer.getConverter(node);
            int len = getconverterMenu().getItemCount();
            for (int i = 0; i < len; i++) {
                JMenuItem item = getconverterMenu().getItem(i);
                if (item != null && item.getActionListeners() != null && item.getActionListeners().length == 1 && item.getActionListeners()[0] instanceof SetConverterActionListener) {
                    SetConverterActionListener scal = (SetConverterActionListener) item.getActionListeners()[0];
                    if (scal.getConverter() == currentConverter)
                        item.setEnabled(false);
                    else
                        item.setEnabled(true);
                }
            }
            getoeTreePopup().show(getOETreeByName(), mouseEvent.getX(), mouseEvent.getY());
        }
    }
    return;
}
Also used : TreePath(javax.swing.tree.TreePath) SimpleIntrospectable(si.ijs.acs.objectexplorer.engine.SimpleIntrospectable) Introspectable(si.ijs.acs.objectexplorer.engine.Introspectable) Converter(si.ijs.acs.objectexplorer.engine.Converter) JMenuItem(javax.swing.JMenuItem)

Example 5 with Converter

use of si.ijs.acs.objectexplorer.engine.Converter in project ACS by ACS-Community.

the class ObjectExplorer method loadConverters.

/**
	 * Load converters....
	 */
private void loadConverters() {
    try {
        String fileName = (String) System.getProperty(CONVERTER_PROPERTY);
        getNotificationBean1().reportDebug("ObjectExplorer::loadConverters", "Startup using '" + CONVERTER_PROPERTY + "' = '" + fileName + "'.");
        if (fileName == null)
            return;
        BufferedReader reader = new BufferedReader(new FileReader(fileName));
        String line = reader.readLine();
        while (line != null) {
            line = line.trim();
            if (line.length() > 0 && !line.startsWith("#")) {
                // line contains class name
                try {
                    Class converterClass = Class.forName(line);
                    Converter converter = (Converter) converterClass.getConstructor(new Class[0]).newInstance(new Object[0]);
                    getNotificationBean1().reportDebug("ObjectExplorer::loadConverters", "Loaded converter '" + line + "' (" + converter.getDescription() + ").");
                    converterRepository.add(converter);
                } catch (Throwable th) {
                    getNotificationBean1().reportDebug("ObjectExplorer::loadConverters", "Failed to load converter '" + line + "'.");
                    th.printStackTrace();
                }
            }
            line = reader.readLine();
        }
        reader.close();
    } catch (Throwable th) {
        th.printStackTrace();
    }
    getNotificationBean1().reportDebug("ObjectExplorer::loadConverters", "Registered " + converterRepository.size() + " converter(s).");
}
Also used : BufferedReader(java.io.BufferedReader) Converter(si.ijs.acs.objectexplorer.engine.Converter) FileReader(java.io.FileReader)

Aggregations

Converter (si.ijs.acs.objectexplorer.engine.Converter)5 JMenuItem (javax.swing.JMenuItem)3 TreePath (javax.swing.tree.TreePath)2 Introspectable (si.ijs.acs.objectexplorer.engine.Introspectable)2 SimpleIntrospectable (si.ijs.acs.objectexplorer.engine.SimpleIntrospectable)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 JMenu (javax.swing.JMenu)1 JSeparator (javax.swing.JSeparator)1 DataElement (si.ijs.acs.objectexplorer.engine.DataElement)1