Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

Commit

Permalink
move loading data right after the splash initialization + use
Browse files Browse the repository at this point in the history
SubMonitors for the parser,...
  • Loading branch information
sgratzl committed Jul 4, 2013
1 parent 0dd848d commit 7c73e74
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 118 deletions.
35 changes: 28 additions & 7 deletions org.caleydo.core/src/org/caleydo/core/internal/Application.java
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.kohsuke.args4j.ClassParser;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
Expand All @@ -35,12 +36,19 @@
* This class controls all aspects of the application's execution
*/
public class Application implements IApplication {
private static Application instance;

public static Application get() {
return instance;
}

private IStartupProcedure startup;

@Override
public Object start(IApplicationContext context) throws Exception {
final Logger log = Logger.create(Application.class);
try {
instance = this;
log.info("Starting Caleydo");

dumpEnvironment(log);
Expand All @@ -59,7 +67,7 @@ public Object start(IApplicationContext context) throws Exception {

// create a select the startup pro
Display display = PlatformUI.createDisplay();
IStartupProcedure startup = selectStartupProcedure(startups, display);
startup = selectStartupProcedure(startups, display);
if (startup == null)
return EXIT_OK; // unstartable
startups = null; // cleanup
Expand All @@ -69,12 +77,7 @@ public Object start(IApplicationContext context) throws Exception {
return EXIT_OK;
}

ApplicationWorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor(startup);

// cleanup
startup = null;

int returnCode = PlatformUI.createAndRunWorkbench(display, advisor);
int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());

log.info("Bye bye!");

Expand All @@ -86,9 +89,12 @@ public Object start(IApplicationContext context) throws Exception {
} catch (Exception e) {
log.error("Caught exception, crashing.", e);
throw e;
} finally {
instance = null;
}
}


/**
* @param startups
* @param display
Expand Down Expand Up @@ -194,4 +200,19 @@ public void run() {
}
});
}


public void runStartup() {
assert startup != null;
startup.run();
}

/**
* @param windowConfigurer
*/
public void postWorkbenchOpen(IWorkbenchWindowConfigurer windowConfigurer) {
startup.postWorkbenchOpen(windowConfigurer);
windowConfigurer.getWindow().getShell().setMaximized(true);
startup = null;
}
}
Expand Up @@ -11,7 +11,6 @@
import org.caleydo.core.gui.perspective.GenomePerspective;
import org.caleydo.core.manager.GeneralManager;
import org.caleydo.core.serialize.ProjectManager;
import org.caleydo.core.startup.IStartupProcedure;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
Expand All @@ -23,27 +22,9 @@
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

import com.google.common.base.Function;

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
private IStartupProcedure startup;

public ApplicationWorkbenchAdvisor(IStartupProcedure startup) {
this.startup = startup;
}
@Override
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(final IWorkbenchWindowConfigurer configurer) {
// Init the core because the workbench must already be initialized for
// the XML startup progress bar

configurer.setTitle("Caleydo - unsaved project");
startup.run(new Function<String, Void>() {
@Override
public Void apply(String data) {
configurer.setTitle(data);
return null;
}
});
return new ApplicationWorkbenchWindowAdvisor(configurer);
}

Expand Down Expand Up @@ -148,10 +129,7 @@ public void postWindowOpen() {

removeNonCaleydoMenuEntries(getWindowConfigurer());

startup.postWorkbenchOpen();
startup = null; // cleanup not used any longer

getWindowConfigurer().getWindow().getShell().setMaximized(true);
Application.get().postWorkbenchOpen(getWindowConfigurer());
}
}
}
Expand Up @@ -22,6 +22,7 @@
import org.caleydo.core.util.logging.Logger;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;

/**
* Parses a delimited text file which contains information on groupings of ids. Creates
Expand All @@ -46,9 +47,8 @@ public GroupingParser(GroupingParseSpecification groupingSpecifications, IDType

@Override
protected void parseFile(BufferedReader reader) throws IOException {

GeneralManager.get().updateProgressLabel("Loading groupings for " + targetIDType);
float progressBarFactor = 100f / numberOfLinesInFile;
SubMonitor monitor = GeneralManager.get().createSubProgressMonitor();
monitor.beginTask("Loading groupings for " + targetIDType, numberOfLinesInFile + 20);

IDSpecification idSpecification = groupingSpecifications.getRowIDSpecification();
IDType sourceIDType = IDType.getIDType(idSpecification.getIdType());
Expand All @@ -68,6 +68,7 @@ else if (sourceIDType.getIdTypeParsingRules() != null)

if (groupingSpecifications.getDataSourcePath() == null) {
Logger.log(new Status(IStatus.INFO, this.toString(), "No path for grouping specified"));
monitor.done();
return;
}
try {
Expand Down Expand Up @@ -145,7 +146,9 @@ else if (sourceIDType.getIdTypeParsingRules() != null)
}
if (line == null)
break;

lineCounter++;
if (lineCounter % 100 == 0)
monitor.worked(100);
// read ID
String[] columns = line.split(groupingSpecifications.getDelimiter());
String originalID = columns[groupingSpecifications.getColumnOfRowIds()];
Expand Down Expand Up @@ -176,12 +179,9 @@ else if (sourceIDType.getIdTypeParsingRules() != null)
group.add(mappedID);
groupListCounter++;
}
lineCounter++;
if (lineCounter % 100 == 0) {
GeneralManager.get().updateProgress((int) (progressBarFactor * lineCounter));
}
}

monitor.setWorkRemaining(20);
// Create the initialization data
perspectiveInitializationDatas = new ArrayList<PerspectiveInitializationData>();

Expand Down Expand Up @@ -217,6 +217,8 @@ else if (sourceIDType.getIdTypeParsingRules() != null)

} catch (IOException ioException) {
throw new IllegalStateException("Could not read file: " + groupingSpecifications.getDataSourcePath());
} finally {
monitor.done();
}
}

Expand Down
Expand Up @@ -18,6 +18,7 @@
import org.caleydo.core.util.logging.Logger;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;

/**
* <p>
Expand Down Expand Up @@ -116,14 +117,12 @@ public final void setTokenSeperator(final String tokenSeparator) {

@Override
protected void parseFile(BufferedReader reader) throws IOException {

GeneralManager.get().updateProgressLabel("Loading ID mapping for " + mappingType);
SubMonitor monitor = GeneralManager.get().createSubProgressMonitor();
String line;

int lineCounter = 0;
calculateNumberOfLinesInFile();

float progressBarFactor = 100f / numberOfLinesInFile;
monitor.beginTask("Loading ID mapping for " + mappingType, numberOfLinesInFile);

while ((line = reader.readLine()) != null && lineCounter <= stopParsingAtLine) {
/**
Expand Down Expand Up @@ -167,9 +166,10 @@ protected void parseFile(BufferedReader reader) throws IOException {

// Update progress bar only on each 100th line
if (lineCounter % 100 == 0) {
GeneralManager.get().updateProgress((int) (progressBarFactor * lineCounter));
monitor.worked(100);
}
lineCounter++;
}
monitor.done();
}
}
Expand Up @@ -38,6 +38,7 @@
import org.caleydo.core.util.logging.Logger;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;

/**
* <p>
Expand Down Expand Up @@ -113,7 +114,6 @@ private void initializTables() {
}
}

calculateNumberOfLinesInFile();
int numberOfDataLines = numberOfLinesInFile - dataSetDescription.getNumberOfHeaderLines();

// prepare for id setting of column IDs
Expand Down Expand Up @@ -241,15 +241,15 @@ else if (sourceColumnIDType.getIdTypeParsingRules() != null)

@Override
protected void parseFile(BufferedReader reader) throws IOException {
SubMonitor monitor = GeneralManager.get().createSubProgressMonitor();
monitor.beginTask("Loading data for: " + dataSetDescription.getDataSetName(), calculateNumberOfLinesInFile());
initializTables();

// Init progress bar
GeneralManager.get().updateProgressLabel("Loading data for: " + dataSetDescription.getDataSetName());
float progressBarFactor = 100f / numberOfLinesInFile;

for (int countHeaderLines = 0; countHeaderLines < dataSetDescription.getNumberOfHeaderLines(); countHeaderLines++) {
reader.readLine();
}
monitor.worked(dataSetDescription.getNumberOfHeaderLines());

List<ColumnDescription> parsingPattern = dataSetDescription.getOrCreateParsingPattern();

Expand Down Expand Up @@ -361,14 +361,15 @@ else if (toIDType.getIdTypeParsingRules() != null)

}
if (lineCounter % 100 == 0) {
GeneralManager.get().updateProgress((int) (progressBarFactor * lineCounter));
monitor.worked(100);
}
lineCounter++;
}

if (parsingErrorOccured) {
Logger.log(new Status(IStatus.ERROR, this.toString(), numberParsingErrorMessage));
}
monitor.done();
}

@Override
Expand Down
33 changes: 18 additions & 15 deletions org.caleydo.core/src/org/caleydo/core/manager/GeneralManager.java
Expand Up @@ -25,7 +25,9 @@
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubMonitor;

/**
* General manager that contains all module managers.
Expand Down Expand Up @@ -77,7 +79,7 @@ public class GeneralManager {
/**
* Progress monitor of the splash. Only valid during startup.
**/
private IProgressMonitor splashProgressMonitor;
private SubMonitor progressMonitor;

private ViewManager viewManager;
private EventPublisher eventPublisher;
Expand All @@ -90,6 +92,7 @@ public class GeneralManager {

private Logger logger = Logger.create(GeneralManager.class);


public void init() {
eventPublisher = EventPublisher.INSTANCE;
viewManager = ViewManager.get();
Expand Down Expand Up @@ -211,22 +214,22 @@ public static boolean canLoadDataCreatedFor(String caleydoVersion) {
}

public void setSplashProgressMonitor(IProgressMonitor splashProgressMonitor) {
this.splashProgressMonitor = splashProgressMonitor;
this.progressMonitor = SubMonitor.convert(splashProgressMonitor, "Loading Caleydo", 1500);
}

public void updateProgress(int percentage) {
if (splashProgressMonitor == null) {
logger.info("Progress update:" + percentage);
} else {
splashProgressMonitor.worked(percentage);
}
}
public SubMonitor createSubProgressMonitor() {
if (progressMonitor == null)
return SubMonitor.convert(new NullProgressMonitor() {
@Override
public void setTaskName(String name) {
logger.info("progress, set task: " + name);
}

public void updateProgressLabel(String message) {
if (splashProgressMonitor == null) {
logger.info("Progress update:" + message);
} else {
splashProgressMonitor.setTaskName(message);
}
@Override
public void beginTask(String name, int totalWork) {
logger.info("begin task: " + name + " (" + totalWork + ")");
}
});
return progressMonitor.newChild(100, SubMonitor.SUPPRESS_SUBTASK);
}
}

0 comments on commit 7c73e74

Please sign in to comment.