Skip to content

Commit

Permalink
Merge pull request #31 from draeger-lab/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
draeger authored Jul 3, 2018
2 parents f5f2922 + cd883a3 commit b0f7459
Show file tree
Hide file tree
Showing 26 changed files with 627 additions and 279 deletions.
31 changes: 0 additions & 31 deletions .classpath

This file was deleted.

7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/.settings
/target
*.log
*.gen
*.gen
.project
.classpath
.properties
/bin/
23 changes: 0 additions & 23 deletions .project

This file was deleted.

5 changes: 0 additions & 5 deletions .settings/org.eclipse.core.resources.prefs

This file was deleted.

5 changes: 0 additions & 5 deletions .settings/org.eclipse.jdt.core.prefs

This file was deleted.

12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<!-- To create your executable file call mvn jfx:jar. The jar-file will be placed at target/jfx/app -->
<!-- To create your executable file call mvn jfx:jar. The jar-file will
be placed at target/jfx/app -->
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
Expand All @@ -83,6 +84,15 @@
<vendor>draeger-lab</vendor>
<mainClass>de.sbtab.main.SBTabMain</mainClass>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
</plugin>
<!--allows us to run tests that use either the “old” JUnit (3 or 4) or
JUnit 5 -->
Expand Down
81 changes: 76 additions & 5 deletions src/main/java/de/sbtab/controller/SBTabController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package de.sbtab.controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Properties;
import java.util.prefs.Preferences;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
Expand All @@ -14,6 +23,39 @@ public class SBTabController {

private static final transient Logger LOGGER = LogManager.getLogger(SBTabController.class);
private static SBMLDocument doc;
private static String filePath = null;

public static String getFilePath() {
return filePath;
}

public static SBMLDocument getDoc() {
return doc;
}

/**
* Set Properties for the programm, at the moment only the file path is saved.
*/
public static void setProperties(){
Writer writer = null;
try
{
writer = new FileWriter( ".properties" );
Properties theProperties = new Properties( System.getProperties() );
if(filePath != null){
theProperties.setProperty( "FilePath", new File(filePath).getParent());
}
else{
theProperties.setProperty( "FilePath", System.getProperty("user.home"));
}
theProperties.store( writer, "Properties of STabEditor" );
}
catch ( IOException e )
{
e.printStackTrace();
}
}

/**
* Save SBML document to a {@link File}.
*
Expand Down Expand Up @@ -50,14 +92,16 @@ public Void call() {
*
* @param path
* absolute path to {@link SBMLDocument}
* @return
* @return
*/
public static SBMLDocument read(String filePath) {
Task<Void> task = new Task<Void>() {
@Override
public Void call() {
try {
SBTabController.filePath = filePath;
doc = SBMLReader.read(new File(filePath));
setProperties();
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -68,20 +112,47 @@ public Void call() {
th.setDaemon(true);
th.start();
try {
th.join();
th.join();
} catch (InterruptedException e) {
e.printStackTrace();
e.printStackTrace();
}
return doc;
}
/**
* Validator of SBML-Files
* @param doc is the input SBML-File
* @return boolean true for valid Document else false plus Logger errors
*/
public static boolean validate(SBMLDocument doc) {
if(doc.checkConsistencyOffline() == 0) {
// the number of Errors of a SBMLFile
int numErrors = doc.checkConsistencyOffline();
if(numErrors == 0) {
return true;
}else {
for(int i = 0; i < doc.checkConsistencyOffline(); i++) {
//get each error and show it
for(int i = 0; i < numErrors; i++) {
LOGGER.error(doc.getError(i));
}
return false;
}
}
/**
* Number of Errors in Document
* @param doc
* @return Number of Errors
*/
public static int numErrors(SBMLDocument doc) {
return doc.checkConsistencyOffline();
}
/**
* Testmethod to get a String-Type Error Code
* @param doc
* @return String-Error
*/
public static String errorToString(SBMLDocument doc) {
int numErrors = doc.checkConsistencyOffline();
String StringError = null;
StringError = doc.getError(0).toString();
return StringError;
}
}
35 changes: 13 additions & 22 deletions src/main/java/de/sbtab/controller/SBTabDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.sbml.jsbml.util.TreeNodeChangeListener;
import org.sbml.jsbml.AbstractTreeNode;
import org.sbml.jsbml.util.TreeNodeRemovedEvent;

public class SBTabDocument<T> implements TreeNodeChangeListener {
Expand All @@ -21,41 +22,31 @@ public class SBTabDocument<T> implements TreeNodeChangeListener {
/**
* Constructor for Document
*
* @param Doc
* @param doc
*
* @param version
* @param pathDoc
*/
public SBTabDocument(T Doc, String version) {
public SBTabDocument(T doc, String pathDoc) {
try {
File temp = File.createTempFile("temp-file-name", ".tmp");
String absolutePath = temp.getAbsolutePath();
pathtempDoc = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
tempDoc = doc;
pathtempDoc = pathDoc;

// TidySBMLWriter.write(Doc, pathtempDoc, "temp-file-name", version);
// File temp = File.createTempFile("temp-file-name", ".tmp");
// String absolutePath = temp.getAbsolutePath();
// pathtempDoc = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator));
// TidySBMLWriter.write(doc, pathtempDoc, "temp-file-name", version);
// tempDoc = SBMLReader.read(new File(tempfilePath));

// ((AbstractTreeNode) tempDoc).addTreeNodeChangeListener(this);

if (tempDoc instanceof AbstractTreeNode) {
((AbstractTreeNode) tempDoc).addTreeNodeChangeListener(this);
}
} catch (Exception e) {
e.printStackTrace();
}

changed = false;
}

/**
* Edit a temporary document
*
* @param x
*/
public void edit(String x) {
try {
changed = true;

} catch (Exception e) {
LOGGER.error("Unable to edit sbml file", e);
}
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/de/sbtab/controller/SBTabElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.sbtab.controller;

/**
* Defines wrapper element for JSBML data node
* */
public interface SBTabElement{
void initialize();
}
50 changes: 32 additions & 18 deletions src/main/java/de/sbtab/controller/SBTabReactionWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,53 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class SBTabReactionWrapper {
public class SBTabReactionWrapper implements SBTabElement {
private Reaction reaction;
private StringProperty reactionName;
private StringProperty reactionId;
private StringProperty reactionSBOTerm;

public SBTabReactionWrapper(Reaction reaction) {
setReaction(reaction);
initialize(reaction);
}

public void initialize(Reaction reaction) {
// TODO: figure out what fields do we need to work with
reactionName = new SimpleStringProperty(reaction.getName());
reactionId = new SimpleStringProperty(reaction.getId());
reactionSBOTerm = new SimpleStringProperty(reaction.getSBOTermID());
}

private void setReaction(Reaction reaction) {
private StringProperty reactionName;
private StringProperty reactionId;
private StringProperty reactionSBOTerm;

public SBTabReactionWrapper(Reaction reaction) {
if (reaction != null) {
setReaction(reaction);
initialize();
}
}

public void initialize() {
// TODO: figure out what fields do we need to work with
reactionName = new SimpleStringProperty(reaction.getName());
reactionId = new SimpleStringProperty(reaction.getId());
reactionSBOTerm = new SimpleStringProperty(reaction.getSBOTermID());
}

private void setReaction(Reaction reaction) {
this.reaction = reaction;
}

public Reaction getReaction() {
return reaction;
}

public void setReactionName(StringProperty reactionName){
this.reactionName = reactionName;
}

public StringProperty getReactionName() {
return reactionName;
}

public void setReactionId(StringProperty reactionId){
this.reactionId = reactionId;
}

public StringProperty getReactionId() {
return reactionId;
}

public void setSBOTerm(StringProperty reactionSBOTerm){
this.reactionSBOTerm = reactionSBOTerm;
}

public StringProperty getSBOTerm() {
return reactionSBOTerm;
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/de/sbtab/main/SBTabMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

import de.sbtab.view.SBTabMainView;
import javafx.application.Application;
import org.sbml.jsbml.SBMLDocument;

public class SBTabMain {

public static void main(String[] args) {
Application.launch(SBTabMainView.class, args);
//Application.launch(SBTabMainView.class, args);
SBTabMainView GUI = new SBTabMainView();
Thread t = new Thread(GUI);
t.start();
}

public static void mainOnFile(SBMLDocument doc) {
//Application.launch(SBTabMainView.class, args);
SBTabMainView GUI = new SBTabMainView(doc);
Thread t = new Thread(GUI);
t.start();
}
}
Loading

0 comments on commit b0f7459

Please sign in to comment.