Skip to content

Commit

Permalink
Add column observer in Appearance UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mbastian committed Dec 30, 2013
1 parent 1b99cc7 commit 9695187
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules/DesktopAppearance/pom.xml
Expand Up @@ -20,6 +20,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>project-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>graph-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>appearance-api</artifactId>
Expand Down
Expand Up @@ -49,12 +49,17 @@ Development and Distribution License("CDDL") (collectively, the
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import org.gephi.appearance.api.AppearanceController;
import org.gephi.appearance.api.AppearanceModel;
import org.gephi.appearance.api.Function;
import org.gephi.appearance.spi.Transformer;
import org.gephi.appearance.spi.TransformerCategory;
import org.gephi.appearance.spi.TransformerUI;
import org.gephi.attribute.api.AttributeModel;
import org.gephi.attribute.api.TableObserver;
import org.gephi.graph.api.GraphController;
import org.gephi.project.api.ProjectController;
import org.gephi.project.api.Workspace;
import org.gephi.project.api.WorkspaceListener;
Expand All @@ -79,6 +84,8 @@ public class AppearanceUIController {
private final Set<AppearanceUIModelListener> listeners;
//Model
private AppearanceUIModel model;
//Observer
private ColumnObserver tableObserver;

public AppearanceUIController() {
final ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
Expand All @@ -98,6 +105,12 @@ public void select(Workspace workspace) {
workspace.add(model);
}
model.select();
if (tableObserver != null) {
tableObserver.destroy();
}
tableObserver = new ColumnObserver(workspace);
tableObserver.start();

firePropertyChangeEvent(AppearanceUIModelEvent.MODEL, oldModel, model);
}

Expand All @@ -117,6 +130,9 @@ public void disable() {
AppearanceUIModel oldModel = model;
model = null;
firePropertyChangeEvent(AppearanceUIModelEvent.MODEL, oldModel, model);
if (tableObserver != null) {
tableObserver.destroy();
}
}
});

Expand Down Expand Up @@ -260,4 +276,43 @@ protected void firePropertyChangeEvent(String propertyName, Object oldValue, Obj
listener.propertyChange(event);
}
}

private class ColumnObserver extends TimerTask {

private final GraphController gc = Lookup.getDefault().lookup(GraphController.class);
private static final int INTERVAL = 500;
private final Timer timer;
private final TableObserver nodeObserver;
private final TableObserver edgeObserver;

public ColumnObserver(Workspace workspace) {
timer = new Timer("RankingColumnObserver", true);
nodeObserver = gc.getAttributeModel(workspace).getNodeTable().getTableObserver();
edgeObserver = gc.getAttributeModel(workspace).getEdgeTable().getTableObserver();
}

@Override
public void run() {
if (nodeObserver.hasTableChanged() || edgeObserver.hasTableChanged()) {
Function oldValue = model.getSelectedFunction();
model.refreshSelectedFunction();
Function newValue = model.getSelectedFunction();
firePropertyChangeEvent(AppearanceUIModelEvent.SELECTED_FUNCTION, oldValue, newValue);
}
}

public void start() {
timer.schedule(this, INTERVAL, INTERVAL);
}

public void stop() {
timer.cancel();
}

public void destroy() {
stop();
nodeObserver.destroy();
edgeObserver.destroy();
}
}
}
Expand Up @@ -123,6 +123,18 @@ private void refreshSelectedFunctions(String elementClass) {
}
}

public boolean refreshSelectedFunction() {
Function sFunction = getSelectedFunction();
if (sFunction != null && sFunction.isAttribute()) {
for (Function func : getSelectedElementClass().equals(AppearanceUIController.NODE_ELEMENT) ? appearanceModel.getNodeFunctions() : appearanceModel.getEdgeFunctions()) {
if(func.equals(sFunction)) {
return false;
}
}
}
return true;
}

public void select() {
}

Expand Down

0 comments on commit 9695187

Please sign in to comment.