Search in sources :

Example 1 with IMemento

use of org.eclipse.ui.IMemento in project tdi-studio-se by Talend.

the class SaveChartSetAsAction method performSave.

/**
     * Performs saving chart set.
     * 
     * @param newChartSet The specified new chart set
     * @param chartSets The changed chart sets
     * @throws WorkbenchException
     * @throws IOException
     */
private void performSave(String newChartSet, List<String> chartSets) throws WorkbenchException, IOException {
    IMemento oldChartSetsMemento = getChartSetsMemento();
    IMemento[] oldMementos;
    if (oldChartSetsMemento == null) {
        oldMementos = new IMemento[0];
    } else {
        oldMementos = oldChartSetsMemento.getChildren(CHART_SET);
    }
    XMLMemento chartSetsMemento = XMLMemento.createWriteRoot(CHART_SETS);
    for (String chartSet : chartSets) {
        for (IMemento memento : oldMementos) {
            if (chartSet.equals(memento.getID()) && !chartSet.equals(newChartSet)) {
                chartSetsMemento.createChild(CHART_SET).putMemento(memento);
                break;
            }
        }
    }
    addNewChartSet(chartSetsMemento, newChartSet);
    StringWriter writer = new StringWriter();
    chartSetsMemento.save(writer);
    Activator.getDefault().getPreferenceStore().setValue(CHART_SETS, writer.getBuffer().toString());
}
Also used : XMLMemento(org.eclipse.ui.XMLMemento) StringWriter(java.io.StringWriter) IMemento(org.eclipse.ui.IMemento)

Example 2 with IMemento

use of org.eclipse.ui.IMemento in project tdi-studio-se by Talend.

the class LoadChartAction method loadChartSet.

/**
     * Loads the given chart set.
     * 
     * @param chartSet The chart set
     * @throws JvmCoreException
     */
private void loadChartSet(String chartSet) throws JvmCoreException {
    loadPredefinedChartSet(chartSet);
    IMemento chartSetsMemento;
    try {
        chartSetsMemento = getChartSetsMemento();
    } catch (WorkbenchException e) {
        throw new JvmCoreException(IStatus.ERROR, Messages.loadChartSetFailedMsg, e);
    } catch (IOException e) {
        throw new JvmCoreException(IStatus.ERROR, Messages.loadChartSetFailedMsg, e);
    }
    if (chartSetsMemento == null) {
        return;
    }
    IMemento[] mementos = chartSetsMemento.getChildren(CHART_SET);
    for (IMemento memento : mementos) {
        if (chartSet.equals(memento.getID())) {
            loadChartSet(memento);
            return;
        }
    }
}
Also used : IOException(java.io.IOException) WorkbenchException(org.eclipse.ui.WorkbenchException) IMemento(org.eclipse.ui.IMemento) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 3 with IMemento

use of org.eclipse.ui.IMemento in project tdi-studio-se by Talend.

the class LoadChartSetAction method loadChartSet.

/**
     * Loads the given memento of chart set.
     * 
     * @param memento The memento
     * @throws JvmCoreException
     */
private void loadChartSet(IMemento memento) throws JvmCoreException {
    IMBeanServer server = section.getJvm().getMBeanServer();
    server.getMonitoredAttributeGroups().clear();
    StringBuffer buffer = new StringBuffer();
    for (IMemento groupMemento : memento.getChildren(GROUP)) {
        IMonitoredMXBeanGroup group = server.addMonitoredAttributeGroup(groupMemento.getID(), AxisUnit.valueOf(groupMemento.getString(UNIT)));
        for (IMemento attributeMemento : groupMemento.getChildren(ATTRIBUTE)) {
            String objectName = attributeMemento.getString(OBJECT_NAME);
            String attributeName = attributeMemento.getID();
            if (attributeExist(objectName, attributeName)) {
                group.addAttribute(objectName, attributeName, getRGB(attributeMemento.getString(COLOR)));
            } else {
                buffer.append('\n');
                buffer.append(objectName + ':' + attributeName);
            }
        }
    }
    if (buffer.length() > 0) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.errorDialogTitle, NLS.bind(Messages.attributeNotSupportedMsg, buffer.toString()));
    }
}
Also used : IMBeanServer(org.talend.designer.runtime.visualization.MBean.IMBeanServer) IMonitoredMXBeanGroup(org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup) IMemento(org.eclipse.ui.IMemento)

Example 4 with IMemento

use of org.eclipse.ui.IMemento in project tdi-studio-se by Talend.

the class LoadChartAction method saveChartSets.

/**
     * Saves the given chart sets that can be subset of previous chart sets.
     * 
     * @param chartSets The chart sets
     * @throws WorkbenchException
     * @throws IOException
     */
private void saveChartSets(List<String> chartSets) throws WorkbenchException, IOException {
    IMemento oldChartSetsMemento = getChartSetsMemento();
    IMemento[] oldMementos;
    if (oldChartSetsMemento == null) {
        oldMementos = new IMemento[0];
    } else {
        oldMementos = oldChartSetsMemento.getChildren(CHART_SET);
    }
    XMLMemento chartSetsMemento = XMLMemento.createWriteRoot(CHART_SETS);
    for (String chartSet : chartSets) {
        for (IMemento memento : oldMementos) {
            if (chartSet.equals(memento.getID())) {
                chartSetsMemento.createChild(CHART_SET).putMemento(memento);
                break;
            }
        }
    }
    StringWriter writer = new StringWriter();
    chartSetsMemento.save(writer);
    Activator.getDefault().getPreferenceStore().setValue(CHART_SETS, writer.getBuffer().toString());
}
Also used : XMLMemento(org.eclipse.ui.XMLMemento) StringWriter(java.io.StringWriter) IMemento(org.eclipse.ui.IMemento)

Example 5 with IMemento

use of org.eclipse.ui.IMemento in project tdi-studio-se by Talend.

the class LoadChartSetAction method saveChartSets.

/**
     * Saves the given chart sets that can be subset of previous chart sets.
     * 
     * @param chartSets The chart sets
     * @throws WorkbenchException
     * @throws IOException
     */
private void saveChartSets(List<String> chartSets) throws WorkbenchException, IOException {
    IMemento oldChartSetsMemento = getChartSetsMemento();
    IMemento[] oldMementos;
    if (oldChartSetsMemento == null) {
        oldMementos = new IMemento[0];
    } else {
        oldMementos = oldChartSetsMemento.getChildren(CHART_SET);
    }
    XMLMemento chartSetsMemento = XMLMemento.createWriteRoot(CHART_SETS);
    for (String chartSet : chartSets) {
        for (IMemento memento : oldMementos) {
            if (chartSet.equals(memento.getID())) {
                chartSetsMemento.createChild(CHART_SET).putMemento(memento);
                break;
            }
        }
    }
    StringWriter writer = new StringWriter();
    chartSetsMemento.save(writer);
    Activator.getDefault().getPreferenceStore().setValue(CHART_SETS, writer.getBuffer().toString());
}
Also used : XMLMemento(org.eclipse.ui.XMLMemento) StringWriter(java.io.StringWriter) IMemento(org.eclipse.ui.IMemento)

Aggregations

IMemento (org.eclipse.ui.IMemento)12 StringWriter (java.io.StringWriter)3 XMLMemento (org.eclipse.ui.XMLMemento)3 IMonitoredMXBeanGroup (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanGroup)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 WorkbenchException (org.eclipse.ui.WorkbenchException)2 JvmCoreException (org.talend.designer.runtime.visualization.JvmCoreException)2 IMBeanServer (org.talend.designer.runtime.visualization.MBean.IMBeanServer)2 IMonitoredMXBeanAttribute (org.talend.designer.runtime.visualization.MBean.IMonitoredMXBeanAttribute)1