Search in sources :

Example 1 with ISWTResourceElement

use of org.talend.designer.runtime.visualization.ISWTResourceElement in project tdi-studio-se by Talend.

the class SWTResourceMonitor method refreshResourcesCache.

/*
     * @see ISWTResourceMonitor#refreshResourcesCache()
     */
@Override
public void refreshResourcesCache() throws JvmCoreException {
    resources.clear();
    ObjectName objectName = validateAgent();
    if (objectName != null) {
        Object attribute = jvm.getMBeanServer().getAttribute(objectName, RESOURCES);
        if (attribute instanceof CompositeData[]) {
            resources = new ArrayList<ISWTResourceElement>(getSWTResourceElements((CompositeData[]) attribute));
        }
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ObjectName(javax.management.ObjectName) ISWTResourceElement(org.talend.designer.runtime.visualization.ISWTResourceElement)

Example 2 with ISWTResourceElement

use of org.talend.designer.runtime.visualization.ISWTResourceElement in project tdi-studio-se by Talend.

the class SWTResourceMonitor method getSWTResourceElements.

/**
     * Gets the SWT resource elements.
     * 
     * @param resourceComposites The resources in composite data array
     * @return The SWT resource elements
     */
private Collection<ISWTResourceElement> getSWTResourceElements(CompositeData[] resourceComposites) {
    Map<String, ISWTResourceElement> newResourceElements = new HashMap<String, ISWTResourceElement>();
    for (CompositeData compositeData : resourceComposites) {
        Object name = compositeData.get(NAME);
        if (!(name instanceof String)) {
            continue;
        }
        ISWTResourceElement element = resourceElements.get(name);
        if (element == null) {
            Object stackTraceElements = compositeData.get(STACK_TRACE);
            if (!(stackTraceElements instanceof CompositeData[])) {
                continue;
            }
            element = new SWTResourceElement((String) name, getStackTrace((CompositeData[]) stackTraceElements));
        }
        newResourceElements.put((String) name, element);
    }
    resourceElements = newResourceElements;
    return resourceElements.values();
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) ISWTResourceElement(org.talend.designer.runtime.visualization.ISWTResourceElement) ISWTResourceElement(org.talend.designer.runtime.visualization.ISWTResourceElement)

Example 3 with ISWTResourceElement

use of org.talend.designer.runtime.visualization.ISWTResourceElement in project tdi-studio-se by Talend.

the class SWTResourceFilteredTree method updateStatusLine.

/**
     * Updates the status line.
     * 
     * @param resourceElements The SWT resource elements
     */
public void updateStatusLine(ISWTResourceElement[] resourceElements) {
    IStatusLineManager manager = actionBars.getStatusLineManager();
    IContributionItem[] items = manager.getItems();
    StatusLineContributionItem resourceCountContributionItem = null;
    for (IContributionItem item : items) {
        if (item instanceof StatusLineContributionItem) {
            resourceCountContributionItem = (StatusLineContributionItem) item;
        }
    }
    // create the status line
    if (resourceCountContributionItem == null) {
        //$NON-NLS-1$
        resourceCountContributionItem = new StatusLineContributionItem("ResourceCountContributionItem");
        manager.add(resourceCountContributionItem);
    }
    if (resourceElements == null) {
        resourceCountContributionItem.setText(Util.ZERO_LENGTH_STRING);
        return;
    }
    Map<String, Integer> resources = new HashMap<String, Integer>();
    for (ISWTResourceElement resourceElement : resourceElements) {
        //$NON-NLS-1$
        String name = resourceElement.getName().split(" ")[0];
        Integer count = resources.get(name);
        resources.put(name, count == null ? 1 : ++count);
    }
    // set text on status line
    List<String> list = new ArrayList<String>(resources.keySet());
    Collections.sort(list);
    StringBuffer buffer = new StringBuffer();
    //$NON-NLS-1$
    buffer.append("Total: ").append(resourceElements.length);
    for (String name : list) {
        //$NON-NLS-1$
        buffer.append(", ").append(name);
        //$NON-NLS-1$
        buffer.append(": ").append(resources.get(name));
    }
    resourceCountContributionItem.setText(buffer.toString());
}
Also used : StatusLineContributionItem(org.eclipse.jface.action.StatusLineContributionItem) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) HashMap(java.util.HashMap) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) ISWTResourceElement(org.talend.designer.runtime.visualization.ISWTResourceElement)

Aggregations

ISWTResourceElement (org.talend.designer.runtime.visualization.ISWTResourceElement)3 HashMap (java.util.HashMap)2 CompositeData (javax.management.openmbean.CompositeData)2 ArrayList (java.util.ArrayList)1 ObjectName (javax.management.ObjectName)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IStatusLineManager (org.eclipse.jface.action.IStatusLineManager)1 StatusLineContributionItem (org.eclipse.jface.action.StatusLineContributionItem)1