Package de.timefinder.core.ui.command

Source Code of de.timefinder.core.ui.command.OptimizeViaUniTimeCommand

/*
*  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.AlgorithmCondition;
import de.timefinder.algo.AlgorithmConditionTime;
import de.timefinder.data.algo.DataPoolSettings;
import net.sf.cpsolver.tt.UniTimeOptimization;
import de.timefinder.core.ui.StatusBarBridge;
import org.springframework.beans.factory.annotation.Autowired;
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 OptimizeViaUniTimeCommand extends TimeFinderCommand {

    public static final String ID = "optimizeViaUniTime";
    private DataPoolSettings settings;

    public OptimizeViaUniTimeCommand() {
        super(ID);
    }

    @Autowired
    public void setSettings(DataPoolSettings settings) {
        this.settings = settings;
    }

    @Override
    protected void doOnce() {
        ApplicationWindow aw = getApplicationWindow();
        aw.getStatusBar().clear();

        // inject via spring and using the same optimizer command class?
        final Algorithm algorithm = new UniTimeOptimization();
        ((UniTimeOptimization) algorithm).setInitialAssignment(true);

        // TODO make seconds editable via GUI
        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.setDataPoolSettings(settings);
                algorithm.setDataPool(dataPool);
                algorithm.setStatusBar(new StatusBarBridge(getApplicationWindow().getStatusBar()));
                algorithm.doWork();
            }
        };
        sw.execute();
    }
}
TOP

Related Classes of de.timefinder.core.ui.command.OptimizeViaUniTimeCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.