~keheliya-gallaba/gephi/maven-build

« back to all changes in this revision

Viewing changes to filters/src/main/java/org/gephi/filters/AttributeColumnPropertyEditor.java

  • Committer: Keheliya Gallaba
  • Date: 2011-08-01 13:01:30 UTC
  • Revision ID: keheliya.gallaba@gmail.com-20110801130130-0u2qgcufi8bvqwxv
Adding Export Plugin, Export Plugin UI, Filters Impl

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2008-2010 Gephi
 
3
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
 
4
Website : http://www.gephi.org
 
5
 
 
6
This file is part of Gephi.
 
7
 
 
8
Gephi is free software: you can redistribute it and/or modify
 
9
it under the terms of the GNU Affero General Public License as
 
10
published by the Free Software Foundation, either version 3 of the
 
11
License, or (at your option) any later version.
 
12
 
 
13
Gephi is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU Affero General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU Affero General Public License
 
19
along with Gephi.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
package org.gephi.filters;
 
22
 
 
23
import java.beans.PropertyEditorSupport;
 
24
import org.gephi.data.attributes.api.AttributeColumn;
 
25
import org.gephi.data.attributes.api.AttributeController;
 
26
import org.gephi.data.attributes.api.AttributeModel;
 
27
import org.gephi.data.attributes.api.AttributeType;
 
28
import org.openide.util.Lookup;
 
29
 
 
30
/**
 
31
 *
 
32
 * @author Mathieu Bastian
 
33
 */
 
34
public class AttributeColumnPropertyEditor extends PropertyEditorSupport {
 
35
    
 
36
    private AttributeColumn column;
 
37
 
 
38
    @Override
 
39
    public void setValue(Object value) {
 
40
        this.column = (AttributeColumn) value;
 
41
    }
 
42
 
 
43
    @Override
 
44
    public Object getValue() {
 
45
        return column;
 
46
    }
 
47
 
 
48
    @Override
 
49
    public String getAsText() {
 
50
        if (column != null) {
 
51
            AttributeModel model = Lookup.getDefault().lookup(AttributeController.class).getModel();
 
52
            if (model.getNodeTable().hasColumn(column.getTitle())) {
 
53
                return "NODE*-*" + column.getId() + "*-*" + column.getType().getTypeString();
 
54
            } else if (model.getEdgeTable().hasColumn(column.getTitle())) {
 
55
                return "EDGE*-*" + column.getId() + "*-*" + column.getType().getTypeString();
 
56
            }
 
57
        }
 
58
        return "null";
 
59
 
 
60
    }
 
61
 
 
62
    @Override
 
63
    public void setAsText(String text) throws IllegalArgumentException {
 
64
        if (!text.equals("null")) {
 
65
            AttributeModel model = Lookup.getDefault().lookup(AttributeController.class).getModel();
 
66
            String[] arr = text.split("\\*-\\*");
 
67
            if (arr[0].equals("NODE")) {
 
68
                column = model.getNodeTable().getColumn(arr[1], AttributeType.valueOf(arr[2]));
 
69
            } else if (arr[0].equals("EDGE")) {
 
70
                column = model.getEdgeTable().getColumn(arr[1], AttributeType.valueOf(arr[2]));
 
71
            }
 
72
        }
 
73
    }
 
74
}