blob: 94d99f1a44f2549c4a6d94d6e453d88b4bc1a7f8 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.ui.initialization;
// TODO: Auto-generated Javadoc
/**
* Notification with information about the actual initialization.
*/
public class InitializationNotification implements IInitializationNotification {
/** The provider title. */
private final IInitializationProvider initializationProvider;
/** The provider title. */
private final String providerTitle;
/** flag is the total initialization has been done. */
private final boolean done;
/** The number of steps done. */
private final int stepsDone;
/** The step title. */
private final String stepTitle;
/** The total steps. */
private final int totalSteps;
/** The progress of step. */
private final double progressOfStep;
/**
* Instantiates a new initialization notification for a done.
*
* @param providerTitle the provider title
* @param totalSteps the total steps
*/
protected InitializationNotification(AbstractInitializationProvider initializationProvider) {
this(initializationProvider, null, initializationProvider.getInitializationTotalSteps(), 1.0);
}
/**
* Instantiates a new initialization notification.
*
* @param providerTitle the provider title
* @param totalSteps the total steps
* @param stepTitle the step title
* @param numberOfStep the number of step
*/
public InitializationNotification(AbstractInitializationProvider initializationProvider, String stepTitle, int stepsDone) {
this(initializationProvider, stepTitle, stepsDone, -1.0);
}
/**
* Instantiates a new initialization notification.
*
* @param providerTitle the provider title
* @param totalSteps the count of total steps
* @param stepTitle the actual steps title
* @param numberOfStep the number of actual step
* @param progressOfStep the progress of actual step
*/
public InitializationNotification(AbstractInitializationProvider initializationProvider, String stepTitle, int stepsDone, double progressOfStep) {
this.initializationProvider = initializationProvider;
this.providerTitle = initializationProvider.getInitializationProviderTitle().trim();
this.totalSteps = Math.max(1, initializationProvider.getInitializationTotalSteps());
if (stepTitle == null || stepTitle.trim().isEmpty()) {
this.stepTitle = null;
}
else {
this.stepTitle = stepTitle.trim();
}
if (stepsDone < 1) {
this.stepsDone = 1;
}
else if (stepsDone > totalSteps) {
this.stepsDone = totalSteps;
}
else {
this.stepsDone = stepsDone;
}
// --- if a negative value is set, no progress of the actual step is available
if (progressOfStep < 0.0) {
this.progressOfStep = -1.0;
}
// --- otherwise the
else {
this.progressOfStep = Math.min(1.0, progressOfStep);
}
this.done = ((this.stepsDone >= this.totalSteps) && (progressOfStep >= 1.0));
}
public boolean isDone() {
return done;
}
/* (non-Javadoc)
* @see org.eclipse.osbp.ui.initialization.IInitializationNotification#getInitializationProvider()
*/
@Override
public IInitializationProvider getInitializationProvider() {
return initializationProvider;
}
/* (non-Javadoc)
* @see org.eclipse.osbp.ui.initialization.IInitializationNotification#getRecommendedProgressValue()
*/
@Override
public double getRecommendedProgressValue() {
// --- calculate the progress value depending on steps level ---
double progressValue = ((double)stepsDone - 1) / ((double)totalSteps);
// --- if available add the step specific progress value ---
if (progressOfStep > 0.0) {
progressValue += progressOfStep / ((double)totalSteps);
}
// --- ensure a progress value between 0.0 and 1.0
return Math.min(1.0, Math.max(0.0, progressValue));
}
/* (non-Javadoc)
* @see org.eclipse.osbp.ui.initialization.IInitializationNotification#getRecommendedProgressTitle(boolean)
*/
@Override
public String getRecommendedProgressTitle(boolean withPercent) {
String progressTitle = providerTitle+" ("+stepsDone+"/"+totalSteps+")";
if (done) {
progressTitle += " done";
}
else if (stepTitle != null) {
progressTitle += " "+stepTitle;
}
if (withPercent) {
double progressValue = getRecommendedProgressValue();
int percent = (int)(progressValue * 100.0);
if ((percent == 0) && (progressValue > 0.0)) {
percent = 1;
}
if ((percent == 100) && (progressValue < 1.0)) {
percent = 99;
}
progressTitle += " - "+percent+"%";
}
return progressTitle;
}
}