提交 048ae20e 编写于 作者: E Eduardo Ramos 提交者: Mathieu Bastian

Add ability to configure element id type in ImportAPI

上级 16541c85
......@@ -499,13 +499,13 @@ public class DataTableTopComponent extends TopComponent implements AWTEventListe
return;
}
if (isShowingNodesTable()) {
if (nodeTable.setPattern(filterTextField.getText(), index)) {
if (nodeTable.setFilterPattern(filterTextField.getText(), index)) {
filterTextField.setBackground(Color.WHITE);
} else {
filterTextField.setBackground(invalidFilterColor);
}
} else if (isShowingEdgesTable()) {
if (edgeTable.setPattern(filterTextField.getText(), index)) {
if (edgeTable.setFilterPattern(filterTextField.getText(), index)) {
filterTextField.setBackground(Color.WHITE);
} else {
filterTextField.setBackground(invalidFilterColor);
......
......@@ -49,6 +49,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.regex.PatternSyntaxException;
import javax.swing.RowFilter;
import javax.swing.table.TableCellRenderer;
......@@ -81,7 +82,7 @@ import org.openide.util.Lookup;
public abstract class AbstractElementsDataTable<T extends Element> {
protected final JXTable table;
protected RowFilter rowFilter;
protected String filterPattern;
protected List<T> selectedElements;
protected final AttributeColumnsController attributeColumnsController;
protected boolean refreshingTable = false;
......@@ -102,7 +103,6 @@ public abstract class AbstractElementsDataTable<T extends Element> {
table.setColumnControlVisible(false);
table.setSortable(true);
table.setAutoCreateRowSorter(true);
table.setRowFilter(rowFilter);
sparkLinesRenderers = new ArrayList<SparkLinesRenderer>();
intervalSetRenderer = new IntervalSetRenderer();
intervalMapRenderer = new IntervalMapRenderer();
......@@ -165,19 +165,33 @@ public abstract class AbstractElementsDataTable<T extends Element> {
return table;
}
public boolean setPattern(String regularExpr, int column) {
public boolean setFilterPattern(String regularExpr, int column) {
try {
if(Objects.equals(filterPattern, regularExpr)){
return true;
}
filterPattern = regularExpr;
if(regularExpr == null || regularExpr.trim().isEmpty()){
table.setRowFilter(null);
}else{
if (!regularExpr.startsWith("(?i)")) { //CASE_INSENSITIVE
regularExpr = "(?i)" + regularExpr;
}
rowFilter = RowFilter.regexFilter(regularExpr, column);
RowFilter rowFilter = RowFilter.regexFilter(regularExpr, column);
table.setRowFilter(rowFilter);
}
} catch (PatternSyntaxException e) {
return false;
}
return true;
}
public String getPattern(){
return filterPattern;
}
public void refreshModel(T[] elements, Column[] cols, GraphModel graphModel, DataTablesModel dataTablesModel) {
showingColumns = cols;
Interval timeBounds = null;
......
......@@ -231,6 +231,13 @@ public interface ContainerLoader {
public void setTimeFormat(TimeFormat timeFormat);
/**
/**
* Sets the type of the id for elements.
*
* @param type id type
*/
public void setElementIdType(ElementIdType type);
* Sets the current time representation, either <code>TIMESTAMP</code> or
* <code>INTERVAL</code>.
* <p>
......
......@@ -88,6 +88,8 @@ public interface ContainerUnloader {
public Class getEdgeTypeLabelClass();
public ElementIdType getElementIdType();
//PARAMETERS GETTERS
public boolean allowSelfLoop();
......
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.io.importer.api;
/**
* Element id type.
*
* @author Mathieu Bastian
*/
public enum ElementIdType {
STRING(String.class),
INTEGER(Integer.class),
LONG(Long.class);
private final Class cls;
ElementIdType(Class cls) {
this.cls = cls;
}
public Class getTypeClass() {
return cls;
}
}
......@@ -68,6 +68,7 @@ import org.gephi.io.importer.api.EdgeDirectionDefault;
import org.gephi.io.importer.api.EdgeDraft;
import org.gephi.io.importer.api.EdgeWeightMergeStrategy;
import org.gephi.io.importer.api.ElementDraft;
import org.gephi.io.importer.api.ElementIdType;
import org.gephi.io.importer.api.Issue;
import org.gephi.io.importer.api.Issue.Level;
import org.gephi.io.importer.api.NodeDraft;
......@@ -99,6 +100,8 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
private EdgeDirectionDefault edgeDefault = EdgeDirectionDefault.MIXED;
private final Object2ObjectMap<String, ColumnDraft> nodeColumns;
private final Object2ObjectMap<String, ColumnDraft> edgeColumns;
//Config
private ElementIdType elementIdType = ElementIdType.STRING;
//Management
private boolean dynamicGraph = false;
private boolean dynamicAttributes = false;
......@@ -525,6 +528,17 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
}
@Override
@Override
public void setElementIdType(ElementIdType type) {
this.elementIdType = type;
report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.ElementIdType", elementIdType.toString()));
}
@Override
public ElementIdType getElementIdType() {
return elementIdType;
}
public boolean verify() {
//Edge weight zero or negative
for (EdgeDraftImpl edge : new NullFilterIterable<EdgeDraftImpl>(edgeList)) {
......@@ -546,6 +560,29 @@ public class ImportContainerImpl implements Container, ContainerLoader, Containe
setEdgeDefault(EdgeDirectionDefault.MIXED);
}
//IdType
if (elementIdType.equals(ElementIdType.INTEGER) || elementIdType.equals(ElementIdType.LONG)) {
try {
for (NodeDraftImpl node : nodeList) {
if (elementIdType.equals(ElementIdType.INTEGER)) {
Integer.parseInt(node.getId());
} else if (elementIdType.equals(ElementIdType.LONG)) {
Long.parseLong(node.getId());
}
}
for (EdgeDraftImpl edge : edgeList) {
if (elementIdType.equals(ElementIdType.INTEGER)) {
Integer.parseInt(edge.getId());
} else if (elementIdType.equals(ElementIdType.LONG)) {
Long.parseLong(edge.getId());
}
}
} catch (NumberFormatException e) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_ElementIdType_Parse_Error", elementIdType), Level.WARNING));
elementIdType = ElementIdType.STRING;
}
}
//Is dynamic graph
for (NodeDraftImpl node : nodeList) {
if (node != null) {
......
......@@ -8,6 +8,7 @@ ImportContainerLog.AddDynamicEdgeColumn = Edge column ''{0}'' (Dynamic {1})
ImportContainerLog.EdgeLabelType = Edge labels are of type ''{0}''
ImportContainerLog.TimeZone = Time zone is set at ''{0}''
ImportContainerLog.MultiGraphCount = Multi-graph with {0} different types
ImportContainerLog.ElementIdType = Element id type set at ''{0}''
ImportContainerException_nodeExist = Duplicated node id=''{0}''
ImportContainerException_UnknowNodeId = Unknown Node id=''{0}''
......@@ -24,6 +25,7 @@ ImportContainerException_Unsupported_Edge_type = Edge types can only have a prim
ImportContainerException_Unsupported_Edge_type_Conflict = Edge label type is of type {0} but should be {1}, the label is ignored
ImportContainerException_Set_EdgeDefault = Default edge type set as ''{0}''
ImportContainerException_Weight_Zero_Ignored = Edge weight is 0, the edge id=''{0}'' is ignored
ImportContainerException_ElementIdType_Parse_Error = The id type is configured to ''{0}'' but some elements id can't be parsed, defaulting to 'STRING'
ImportContainerException_Negative_Weight = Edge id=''{0}'' has a negative weight
ImportContainerException_Column_Type_Mismatch = A column ''{0}'' already exists but with a different type=''{1}''
......
......@@ -52,6 +52,7 @@ import org.gephi.graph.api.Node;
import org.gephi.io.importer.api.ContainerUnloader;
import org.gephi.io.importer.api.EdgeDirection;
import org.gephi.io.importer.api.EdgeDraft;
import org.gephi.io.importer.api.ElementIdType;
import org.gephi.io.importer.api.NodeDraft;
import org.gephi.io.processor.spi.Processor;
import org.gephi.project.api.ProjectController;
......@@ -111,6 +112,8 @@ public class DefaultProcessor extends AbstractProcessor implements Processor {
if (container.getEdgeTypeLabelClass() != null) {
// configuration.setEdgeLabelType(container.getEdgeTypeLabelClass());
}
configuration.setNodeIdType(container.getElementIdType().getTypeClass());
configuration.setEdgeIdType(container.getElementIdType().getTypeClass());
graphController.getGraphModel(workspace).setConfiguration(configuration);
}
......@@ -137,8 +140,10 @@ public class DefaultProcessor extends AbstractProcessor implements Processor {
int addedNodes = 0, addedEdges = 0;
//Create all nodes
ElementIdType elementIdType = container.getElementIdType();
for (NodeDraft draftNode : container.getNodes()) {
String id = draftNode.getId();
String idString = draftNode.getId();
Object id = toElementId(elementIdType, idString);
Node node = graph.getNode(id);
if (node == null) {
node = factory.newNode(id);
......@@ -153,11 +158,12 @@ public class DefaultProcessor extends AbstractProcessor implements Processor {
//Create all edges and push to data structure
for (EdgeDraft draftEdge : container.getEdges()) {
String id = draftEdge.getId();
String idString = draftEdge.getId();
Object id = toElementId(elementIdType, idString);
String sourceId = draftEdge.getSource().getId();
String targetId = draftEdge.getTarget().getId();
Node source = graph.getNode(sourceId);
Node target = graph.getNode(targetId);
Node source = graph.getNode(toElementId(elementIdType, sourceId));
Node target = graph.getNode(toElementId(elementIdType, targetId));
Object type = draftEdge.getType();
int edgeType = graphModel.addEdgeType(type);
......@@ -197,4 +203,20 @@ public class DefaultProcessor extends AbstractProcessor implements Processor {
Progress.finish(progressTicket);
}
private Object toElementId(ElementIdType elementIdType, String idString) {
Object id;
switch (elementIdType) {
case INTEGER:
id = Integer.parseInt(idString);
break;
case LONG:
id = Long.parseLong(idString);
break;
default:
id = idString;
break;
}
return id;
}
}
......@@ -40,9 +40,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>swingx</artifactId>
<version>1.6.1</version>
<groupId>org.swinglabs.swingx</groupId>
<artifactId>swingx-all</artifactId>
<version>1.6.5-1</version>
</dependency>
<dependency>
<groupId>org.jdesktop</groupId>
......@@ -62,7 +62,7 @@
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout</artifactId>
<version>3.7.1</version>
<version>3.7.4</version>
</dependency>
<dependency>
<groupId>net.java.dev</groupId>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册