Skip to content

Commit ab94ad0

Browse files
Fix #2061 - Added Contains under the Attribute category in Filters
1 parent 6e063a4 commit ab94ad0

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
Copyright 2008-2010 Gephi
3+
Authors : Mathieu Bastian <[email protected]>
4+
Website : http://www.gephi.org
5+
6+
This file is part of Gephi.
7+
8+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9+
10+
Copyright 2011 Gephi Consortium. All rights reserved.
11+
12+
The contents of this file are subject to the terms of either the GNU
13+
General Public License Version 3 only ("GPL") or the Common
14+
Development and Distribution License("CDDL") (collectively, the
15+
"License"). You may not use this file except in compliance with the
16+
License. You can obtain a copy of the License at
17+
http://gephi.org/about/legal/license-notice/
18+
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
19+
specific language governing permissions and limitations under the
20+
License. When distributing the software, include this License Header
21+
Notice in each file and include the License files at
22+
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
23+
License Header, with the fields enclosed by brackets [] replaced by
24+
your own identifying information:
25+
"Portions Copyrighted [year] [name of copyright owner]"
26+
27+
If you wish your version of this file to be governed by only the CDDL
28+
or only the GPL Version 3, indicate your decision by adding
29+
"[Contributor] elects to include this software in this distribution
30+
under the [CDDL or GPL Version 3] license." If you do not indicate a
31+
single choice of license, a recipient has the option to distribute
32+
your version of this file under either the CDDL, the GPL Version 3 or
33+
to extend the choice of license to its licensees as provided above.
34+
However, if you add GPL Version 3 code and therefore, elected the GPL
35+
Version 3 license, then the option applies only if the new code is
36+
made subject to such option by the copyright holder.
37+
38+
Contributor(s):
39+
40+
Portions Copyrighted 2011 Gephi Consortium.
41+
*/
42+
43+
package org.gephi.filters.plugin.attribute;
44+
45+
import java.util.ArrayList;
46+
import java.util.List;
47+
import javax.swing.JPanel;
48+
import org.gephi.filters.api.FilterLibrary;
49+
import org.gephi.filters.plugin.AbstractAttributeFilter;
50+
import org.gephi.filters.plugin.AbstractAttributeFilterBuilder;
51+
import org.gephi.filters.spi.Category;
52+
import org.gephi.filters.spi.CategoryBuilder;
53+
import org.gephi.filters.spi.EdgeFilter;
54+
import org.gephi.filters.spi.Filter;
55+
import org.gephi.filters.spi.FilterBuilder;
56+
import org.gephi.filters.spi.NodeFilter;
57+
import org.gephi.graph.api.AttributeUtils;
58+
import org.gephi.graph.api.Column;
59+
import org.gephi.graph.api.Element;
60+
import org.gephi.graph.api.Graph;
61+
import org.gephi.graph.api.GraphController;
62+
import org.gephi.graph.api.GraphModel;
63+
import org.gephi.project.api.Workspace;
64+
import org.openide.util.Lookup;
65+
import org.openide.util.NbBundle;
66+
import org.openide.util.lookup.ServiceProvider;
67+
68+
/**
69+
* @author Sukankana Chakraborty
70+
*/
71+
@ServiceProvider(service = CategoryBuilder.class)
72+
public class AttributeContainsBuilder implements CategoryBuilder {
73+
74+
private final static Category CONTAINS = new Category(
75+
NbBundle.getMessage(AttributeEqualBuilder.class, "AttributeContainsBuilder.name"),
76+
null,
77+
FilterLibrary.ATTRIBUTES);
78+
79+
@Override
80+
public Category getCategory() {
81+
return CONTAINS;
82+
}
83+
84+
@Override
85+
public FilterBuilder[] getBuilders(Workspace workspace) {
86+
List<FilterBuilder> builders = new ArrayList<>();
87+
GraphModel am = Lookup.getDefault().lookup(GraphController.class).getGraphModel(workspace);
88+
for (Column col : am.getNodeTable()) {
89+
System.out.println(col.isArray());
90+
if (col.isArray()) {
91+
AttributeContainsFilterBuilder b = new AttributeContainsFilterBuilder(col);
92+
/* to do: insert loop to add each element in the list */
93+
builders.add(b);
94+
}
95+
}
96+
for (Column col : am.getEdgeTable()) {
97+
if (col.isArray()) {
98+
AttributeContainsFilterBuilder b = new AttributeContainsFilterBuilder(col);
99+
/* to do: insert loop to add each element in the list */
100+
builders.add(b);
101+
}
102+
}
103+
return builders.toArray(new FilterBuilder[0]);
104+
}
105+
106+
private static class AttributeContainsFilterBuilder extends AbstractAttributeFilterBuilder {
107+
108+
public AttributeContainsFilterBuilder(Column column) {
109+
super(column,
110+
CONTAINS,
111+
NbBundle.getMessage(AttributeEqualBuilder.class, "AttributeContainsBuilder.description"),
112+
null);
113+
}
114+
115+
@Override
116+
public AttributeContainsFilter getFilter(Workspace workspace) {
117+
return AttributeUtils.isNodeColumn(column) ? new AttributeContainsFilter.Node(column) :
118+
new AttributeContainsFilter.Edge(column);
119+
}
120+
121+
@Override
122+
public JPanel getPanel(Filter filter) {
123+
return null;
124+
}
125+
}
126+
127+
public static abstract class AttributeContainsFilter<K extends Element> extends AbstractAttributeFilter<K> {
128+
129+
public AttributeContainsFilter(Column column) {
130+
super(NbBundle.getMessage(AttributeEqualBuilder.class, "AttributeContainsBuilder.name"),
131+
column);
132+
}
133+
134+
@Override
135+
public boolean init(Graph graph) {
136+
if (AttributeUtils.isNodeColumn(column)) {
137+
return graph.getNodeCount() != 0;
138+
} else if (AttributeUtils.isEdgeColumn(column)) {
139+
return graph.getEdgeCount() != 0;
140+
}
141+
return true;
142+
}
143+
144+
@Override
145+
public boolean evaluate(Graph graph, Element element) {
146+
return element.getAttribute(column) != null;
147+
}
148+
149+
@Override
150+
public void finish() {
151+
}
152+
153+
public static class Node extends AttributeContainsFilter<org.gephi.graph.api.Node> implements NodeFilter {
154+
155+
public Node(Column column) {
156+
super(column);
157+
}
158+
}
159+
160+
public static class Edge extends AttributeContainsFilter<org.gephi.graph.api.Edge> implements EdgeFilter {
161+
162+
public Edge(Column column) {
163+
super(column);
164+
}
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)