Search in sources :

Example 1 with Tunable

use of org.cytoscape.work.Tunable in project cytoscape-impl by cytoscape.

the class SyncTunableHandlerTest method testSyncTunableHandler.

@Test
public void testSyncTunableHandler() throws Exception {
    TunableHolder th = new TunableHolder();
    final Field stringField = th.getClass().getField("tstring");
    final Tunable tun = stringField.getAnnotation(Tunable.class);
    SyncTunableHandler syncHandler = new SyncTunableHandler(stringField, th, tun);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("tstring", "hello");
    syncHandler.setValueMap(map);
    assertEquals("goodbye", th.tstring);
    syncHandler.handle();
    assertEquals("hello", th.tstring);
}
Also used : Field(java.lang.reflect.Field) Tunable(org.cytoscape.work.Tunable) Test(org.junit.Test)

Example 2 with Tunable

use of org.cytoscape.work.Tunable in project cytoscape-impl by cytoscape.

the class CyGroupAggregationSettings method getAttrSelection.

@Tunable(description = "Attribute to override:", groups = { "Attribute Aggregation Settings", "Aggregation Overrides" }, dependsOn = "enableAttributeAggregation=true", params = "displayState=collapsed", gravity = 20.0)
public ListSingleSelection<String> getAttrSelection() {
    // Now, build the list of attributes -- we'll focus on
    // node attributes for now
    List<String> attrList = new ArrayList<String>();
    currentNetwork = appMgr.getCurrentNetwork();
    if (currentNetwork != null) {
        for (CyColumn column : currentNetwork.getDefaultNodeTable().getColumns()) {
            if (column.getName().equals(CyNetwork.SUID))
                continue;
            attrList.add(column.getName());
        }
    } else {
        attrList.add("No attributes available");
    }
    attrSelection = new ListSingleSelection<String>(attrList);
    return attrSelection;
}
Also used : ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) Tunable(org.cytoscape.work.Tunable)

Example 3 with Tunable

use of org.cytoscape.work.Tunable in project cytoscape-impl by cytoscape.

the class CyGroupAggregationSettings method getAttrType.

@Tunable(description = "Attribute Type:", groups = { "Attribute Aggregation Settings", "Aggregation Overrides" }, dependsOn = "enableAttributeAggregation=true", listenForChange = { "AttrSelection" }, gravity = 21.0)
public String getAttrType() {
    if (currentNetwork == null || attrSelection == null || attrSelection.getSelectedValue() == null || attrSelection.getSelectedValue().length() == 0) {
        if (aggregationType != null)
            aggregationType.setPossibleValues(cyAggManager.getAggregators(NoneAggregator.class));
        else
            aggregationType = new ListSingleSelection<Aggregator<?>>(cyAggManager.getAggregators(NoneAggregator.class));
        return "-- No Network --";
    }
    // Get the attribute from the selection
    String columnName = attrSelection.getSelectedValue();
    CyTable nodeTable = currentNetwork.getDefaultNodeTable();
    CyColumn column = nodeTable.getColumn(columnName);
    if (column == null)
        return "-- No Such Column -- ";
    if (aggregationType != null) {
        if (column.getType().equals(List.class))
            aggregationType.setPossibleValues(cyAggManager.getListAggregators(column.getListElementType()));
        else
            aggregationType.setPossibleValues(cyAggManager.getAggregators(column.getType()));
    } else {
        if (column.getType().equals(List.class))
            aggregationType = new ListSingleSelection<Aggregator<?>>(cyAggManager.getListAggregators(column.getListElementType()));
        else
            aggregationType = new ListSingleSelection<Aggregator<?>>(cyAggManager.getAggregators(column.getType()));
    }
    // if (aggregationType.getSelectedValue() == null) {
    if (group == null) {
        Aggregator<?> type = settings.getOverrideAggregation(column);
        if (type != null)
            aggregationType.setSelectedValue(type);
    } else {
        Aggregator<?> type = settings.getOverrideAggregation(group, column);
        if (type != null)
            aggregationType.setSelectedValue(type);
    }
    // }
    // Get it's type
    String t = column.getType().getSimpleName();
    if (column.getType().equals(List.class))
        t += " of " + column.getListElementType().getSimpleName() + "s";
    return t;
}
Also used : CyTable(org.cytoscape.model.CyTable) NoneAggregator(org.cytoscape.group.internal.data.aggregators.NoneAggregator) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) CyColumn(org.cytoscape.model.CyColumn) Tunable(org.cytoscape.work.Tunable)

Example 4 with Tunable

use of org.cytoscape.work.Tunable in project cytoscape-api by cytoscape.

the class AbstractGUITunableHandlerTest method initialise.

@Before
public void initialise() throws Exception {
    final HasAnnotatedField hasAnnotatedField = new HasAnnotatedField();
    final Field annotatedIntField = hasAnnotatedField.getClass().getField("annotatedInt");
    final Tunable annotatedIntTunable = annotatedIntField.getAnnotation(Tunable.class);
    fieldHandler = new SimpleGUITunableHandler(annotatedIntField, hasAnnotatedField, annotatedIntTunable);
    final HasAnnotatedMethod hasAnnotatedMethod = new HasAnnotatedMethod();
    final Method setter = hasAnnotatedMethod.getClass().getMethod("setAnnotatedInt", int.class);
    final Method getter = hasAnnotatedMethod.getClass().getMethod("getAnnotatedInt");
    final Tunable annotatedMethodTunable = getter.getAnnotation(Tunable.class);
    methodHandler = new SimpleGUITunableHandler(getter, setter, hasAnnotatedMethod, annotatedMethodTunable);
    final Method setterS = hasAnnotatedMethod.getClass().getMethod("setAnnotatedString", String.class);
    final Method getterS = hasAnnotatedMethod.getClass().getMethod("getAnnotatedString");
    final Tunable annotatedMethodTunableS = getterS.getAnnotation(Tunable.class);
    methodHandlerS = new SimpleGUITunableHandler(getterS, setterS, hasAnnotatedMethod, annotatedMethodTunableS);
}
Also used : Field(java.lang.reflect.Field) Tunable(org.cytoscape.work.Tunable) Method(java.lang.reflect.Method) Before(org.junit.Before)

Aggregations

Tunable (org.cytoscape.work.Tunable)4 Field (java.lang.reflect.Field)2 CyColumn (org.cytoscape.model.CyColumn)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 NoneAggregator (org.cytoscape.group.internal.data.aggregators.NoneAggregator)1 CyTable (org.cytoscape.model.CyTable)1 ListSingleSelection (org.cytoscape.work.util.ListSingleSelection)1 Before (org.junit.Before)1 Test (org.junit.Test)1