/*
* Copyright 2009 Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* under the License.
*/
package de.timefinder.core.ui.command;
import de.timefinder.algo.Algorithm;
import de.timefinder.algo.AlgorithmConditionTime;
import de.timefinder.core.ui.StatusBarBridge;
import org.springframework.richclient.application.ApplicationWindow;
/**
* This class makes the algorithm available for the user
*
* @author Peter Karich, peat_hal ‘at’ users ‘dot’ sourceforge ‘dot’ net
*/
public class OptimizeViaNcpCommand extends TimeFinderCommand {
public static final String ID = "optimizeViaNcp";
private Algorithm algorithm;
public OptimizeViaNcpCommand() {
super(ID);
}
public void setAlgorithm(Algorithm algorithm) {
this.algorithm = algorithm;
}
@Override
protected void doOnce() {
ApplicationWindow aw = getApplicationWindow();
aw.getStatusBar().clear();
// TODO make variable
int sec = 5 * 60;
algorithm.setCondition(new AlgorithmConditionTime(sec));
String msg = tr.get(ID + ".startTask", sec / 60.0f);
aw.getStatusBar().getProgressMonitor().taskStarted(msg, -1);
MySwingWorker sw = new MySwingWorker(ID) {
@Override
protected void myconstruct() throws Exception {
algorithm.setDataPool(dataPool);
algorithm.setStatusBar(new StatusBarBridge(getApplicationWindow().getStatusBar()));
algorithm.doWork();
}
};
sw.execute();
}
}