Package sos.scheduler.editor.conf.forms

Source Code of sos.scheduler.editor.conf.forms.JobAssistentTasksForm

/********************************************************* begin of preamble
**
** Copyright (C) 2003-2010 Software- und Organisations-Service GmbH.
** All rights reserved.
**
** This file may be used under the terms of either the
**
**   GNU General Public License version 2.0 (GPL)
**
**   as published by the Free Software Foundation
**   http://www.gnu.org/licenses/gpl-2.0.txt and appearing in the file
**   LICENSE.GPL included in the packaging of this file.
**
** or the
** 
**   Agreement for Purchase and Licensing
**
**   as offered by Software- und Organisations-Service GmbH
**   in the respective terms of supply that ship with this file.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
** IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
** POSSIBILITY OF SUCH DAMAGE.
********************************************************** end of preamble*/
package sos.scheduler.editor.conf.forms;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.jdom.Element;
import com.swtdesigner.SWTResourceManager;
import sos.scheduler.editor.app.MainWindow;
import sos.scheduler.editor.app.Messages;
import sos.scheduler.editor.app.Options;
import sos.scheduler.editor.app.ResourceManager;
import sos.scheduler.editor.app.Utils;
import sos.scheduler.editor.conf.ISchedulerUpdate;
import sos.scheduler.editor.conf.SchedulerDom;
import sos.scheduler.editor.conf.listeners.JobListener;
import sos.scheduler.editor.conf.listeners.JobsListener;
import sos.scheduler.editor.app.Editor;

public class JobAssistentTasksForm

  private Text              txtTask      = null;

  private JobListener       joblistener  = null;

  private SchedulerDom      dom          = null;

  private ISchedulerUpdate  update       = null;

  private Button            butFinish    = null;

  private Button            butCancel    = null;

  private Button            butNext      = null;

  private Button            butShow      = null;   

  private Text              txtMinTasks  = null;

  /** Wer hat ihn aufgerufen, der Job assistent oder job_chain assistent*/
  private int               assistentType= -1;

  private Shell             tasksShell   = null;

  private Combo             jobname      = null;

  private Button            butBack      = null;

  private Element           jobBackUp    = null

  private JobMainForm           jobForm      = null;

  /** Hilsvariable f�r das Schliessen des Dialogs.
   * Das wird gebraucht wenn das Dialog �ber den "X"-Botten (oben rechts vom Dialog) geschlossen wird .*/
  private boolean           closeDialog  = false;        


  public JobAssistentTasksForm(SchedulerDom dom_, ISchedulerUpdate update_, Element job_, int assistentType_) { 
    dom = dom_;
    update = update_;   
    assistentType = assistentType_;
    joblistener = new JobListener(dom, job_, update);       
  }

  private void init() {
    Element job = joblistener.getJob();
    if(job != null && Utils.getAttributeValue("tasks", job).equals("unbounded")) {
      job.removeAttribute("tasks");     
    }
  }

  public void showTasksForm() {

    init();

    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    tasksShell= new Shell(MainWindow.getSShell(), SWT.CLOSE | SWT.TITLE | SWT.APPLICATION_MODAL | SWT.BORDER);
    tasksShell.addShellListener(new ShellAdapter() {
      public void shellClosed(final ShellEvent e) {
        if(!closeDialog)
          close();
        e.doit = tasksShell.isDisposed();
      }
    });
    tasksShell.setLayout(gridLayout);
    tasksShell.setSize(473, 166);
    tasksShell.setImage(ResourceManager.getImageFromResource("/sos/scheduler/editor/editor.png"));
    String step = "  ";
    if (Utils.getAttributeValue("order", joblistener.getJob()).equalsIgnoreCase("yes"))
      step = step + " [Step 4 of 9]";
    else
      step = step + " [Step 4 of 8]";
    tasksShell.setText("Tasks" + step);

    {
      if(Utils.getAttributeValue("tasks", joblistener.getJob()) != null &&
          Utils.getAttributeValue("tasks", joblistener.getJob()).equals("unbounded")) {
        joblistener.setTasks("");   
      }
    }

    {
      final Group jobGroup = new Group(tasksShell, SWT.NONE);
      jobGroup.setText("Job " + Utils.getAttributeValue("name", joblistener.getJob()));
      final GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, true, 2, 1);
      jobGroup.setLayoutData(gridData);
      final GridLayout gridLayout_1 = new GridLayout();
      gridLayout_1.marginWidth = 10;
      gridLayout_1.marginTop = 10;
      gridLayout_1.marginRight = 10;
      gridLayout_1.marginLeft = 10;
      gridLayout_1.marginHeight = 10;
      jobGroup.setLayout(gridLayout_1);

      final Composite composite_1 = new Composite(jobGroup, SWT.NONE);
      composite_1.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
      final GridLayout gridLayout_3 = new GridLayout();
      gridLayout_3.marginWidth = 0;
      gridLayout_3.marginRight = 5;
      gridLayout_3.numColumns = 4;
      composite_1.setLayout(gridLayout_3);

      {
        final Label tasksLabel = new Label(composite_1, SWT.NONE);
        final GridData gridData_1 = new GridData(GridData.FILL, GridData.CENTER, false, false);
        gridData_1.widthHint = 57;
        tasksLabel.setLayoutData(gridData_1);
        tasksLabel.setText("Tasks");
      }
      txtTask = new Text(composite_1, SWT.BORDER);
      txtTask.setFocus();
      txtTask.addModifyListener(new ModifyListener() {
        public void modifyText(final ModifyEvent e) {
          if(txtTask.getText() !=  null && txtTask.getText().trim().length() > 0)  {
            if(Utils.isNumeric(txtTask.getText())) {
              joblistener.setTasks(txtTask.getText());
            } else {             
              MainWindow.message(tasksShell, sos.scheduler.editor.app.Messages.getString("assistent.no_numeric"), SWT.ICON_WARNING | SWT.OK );
            }
            txtTask.setFocus();
          }
        }
      });
      txtTask.setFocus();
      final GridData gridData_5 = new GridData(GridData.FILL, GridData.CENTER, false, false);
      gridData_5.widthHint = 112;
      gridData_5.minimumWidth = 100;
      txtTask.setLayoutData(gridData_5);     
      txtTask.setText(joblistener.getTasks());

      final Label minimumTasksLabel = new Label(composite_1, SWT.RIGHT);
      final GridData gridData_3 = new GridData(GridData.FILL, GridData.CENTER, false, false);
      gridData_3.widthHint = 95;
      minimumTasksLabel.setLayoutData(gridData_3);
      minimumTasksLabel.setText("Minimum Tasks");

      txtMinTasks = new Text(composite_1, SWT.BORDER);
      txtMinTasks.setText(joblistener.getMintasks());
      txtMinTasks.addModifyListener(new ModifyListener() {
        public void modifyText(final ModifyEvent e) {
          if(txtMinTasks.getText() !=  null && txtMinTasks.getText().trim().length() > 0)  {
            if(Utils.isNumeric(txtMinTasks.getText())) {
              joblistener.setMintasks(txtMinTasks.getText());
            } else {             
              MainWindow.message(tasksShell, sos.scheduler.editor.app.Messages.getString("assistent.no_numeric"), SWT.ICON_WARNING | SWT.OK );
            }
          }
        }
      });
      final GridData gridData_4 = new GridData(GridData.FILL, GridData.CENTER, true, false);
      gridData_4.widthHint = 89;
      txtMinTasks.setLayoutData(gridData_4);
    }

    {
      final Composite composite = new Composite(tasksShell, SWT.NONE);
      composite.setLayoutData(new GridData());
      final GridLayout gridLayout_2 = new GridLayout();
      gridLayout_2.marginWidth = 0;
      composite.setLayout(gridLayout_2);
      {
        butCancel = new Button(composite, SWT.NONE);
        butCancel.addSelectionListener(new SelectionAdapter() {
          public void widgetSelected(final SelectionEvent e) {
            close();
          }
        });
        butCancel.setText("Cancel");
      }
    }

    final Composite composite_2 = new Composite(tasksShell, SWT.NONE);
    final GridData gridData = new GridData(GridData.END, GridData.CENTER, false, false);
    gridData.widthHint = 211;
    composite_2.setLayoutData(gridData);
    final GridLayout gridLayout_4 = new GridLayout();
    gridLayout_4.marginWidth = 0;
    gridLayout_4.numColumns = 5;
    composite_2.setLayout(gridLayout_4);

    {
      butShow = new Button(composite_2, SWT.NONE);
      butShow.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
      butShow.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
          if(!checkTasks()) return;                   
          Utils.showClipboard(Utils.getElementAsString(joblistener.getJob()), tasksShell, false, null, false, null, false);
          txtTask.setFocus();
        }
      });
      butShow.setText("Show");
    }

    {
      butFinish = new Button(composite_2, SWT.NONE);
      butFinish.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
      butFinish.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
          doFinish();

        }
      });
      butFinish.setText("Finish");
    }

    butBack = new Button(composite_2, SWT.NONE);
    butBack.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(final SelectionEvent e) {
        JobAssistentImportJobParamsForm paramsForm = new JobAssistentImportJobParamsForm(dom, update, joblistener.getJob(), assistentType);         
        paramsForm.showAllImportJobParams(joblistener.getInclude());
        if(jobname != null)                          
          paramsForm.setJobname(jobname);
        //if(jobBackUp != null)
        paramsForm.setBackUpJob(jobBackUp, jobForm);

        closeDialog = true;
        tasksShell.dispose();
      }
    });
    butBack.setText("Back");
    {
      butNext = new Button(composite_2, SWT.NONE);
      butNext.setFont(SWTResourceManager.getFont("", 8, SWT.BOLD));
      butNext.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false));
      butNext.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) { 
          doNext();         
        }
      });
      butNext.setText("Next");
    }

    Utils.createHelpButton(composite_2, "assistent.tasks", tasksShell);       
    tasksShell.layout();
    setToolTipText();
    java.awt.Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();   
    tasksShell.setBounds((screen.width - tasksShell.getBounds().width) /2,
        (screen.height - tasksShell.getBounds().height) /2,
        tasksShell.getBounds().width,
        tasksShell.getBounds().height);
    tasksShell.open();
  }

  public void setToolTipText() {
    butCancel.setToolTipText(Messages.getTooltip("assistent.cancel"));
    butNext.setToolTipText(Messages.getTooltip("assistent.next"));
    butShow.setToolTipText(Messages.getTooltip("assistent.show"));
    butFinish.setToolTipText(Messages.getTooltip("assistent.finish"));
    txtTask.setToolTipText(Messages.getTooltip("assistent.task"));
    txtMinTasks.setToolTipText(Messages.getTooltip("assistent.min_task"));
    butBack.setToolTipText(Messages.getTooltip("butBack"));
  }


  /**
   * �berpr�fung
   * min_tasks darf tasks nicht �berschreiten
   */
  private boolean checkTasks() {       
    if((txtTask.getText() != null && txtTask.getText().trim().length() > 0) &&
        (txtMinTasks.getText() != null && txtMinTasks.getText().trim().length() > 0)) {
      if(Integer.parseInt(txtMinTasks.getText()) > Integer.parseInt(txtTask.getText())) {
        MainWindow.message(tasksShell, sos.scheduler.editor.app.Messages.getString("assistent.error.min_task_too_large"), SWT.ICON_WARNING | SWT.OK );
        return false;
      }     
    }

    if((txtTask.getText() != null && txtTask.getText().trim().length() == 0) &&
        (txtMinTasks.getText() != null && txtMinTasks.getText().trim().length() > 0)) {
      if(Integer.parseInt(txtMinTasks.getText()) > 1) {
        MainWindow.message(tasksShell, sos.scheduler.editor.app.Messages.getString("min_task_to_great"), SWT.ICON_WARNING | SWT.OK );
        return false;
      }

    }
    return true;
  }

  private void close() {
    int cont = MainWindow.message(tasksShell, sos.scheduler.editor.app.Messages.getString("assistent.cancel"), SWT.ICON_WARNING | SWT.OK |SWT.CANCEL );
    if(cont == SWT.OK) {
      if(jobBackUp != null)
        joblistener.getJob().setContent(jobBackUp.cloneContent());
      tasksShell.dispose();
    }
  }



  private void doNext() {

    Utils.startCursor(tasksShell);

    if(!checkTasks())
      return;   

    Element job = joblistener.getJob();   

    if(job.getChild("description") == null) {

      //Wizzard ohne Jobbeschreibung wurde aufgerufen.
      JobAssistentExecuteForms execute = new JobAssistentExecuteForms(dom, update, job, assistentType);
      execute.showExecuteForm();
      if(jobname != null)                          
        execute.setJobname(jobname);     
      execute.setBackUpJob(jobBackUp, jobForm);

    } else if(job.getChild("process") != null) {

      JobAssistentProcessForms process = new JobAssistentProcessForms(dom, update, job, assistentType);
      process.showProcessForm()
      if(jobname != null)                          
        process.setJobname(jobname);     
      process.setBackUpJob(jobBackUp, jobForm);

    } else {

      JobAssistentScriptForms script = new JobAssistentScriptForms(dom, update, job, assistentType);
      script.showScriptForm()
      if(jobname != null)                          
        script.setJobname(jobname);     
      script.setBackUpJob(jobBackUp, jobForm);

    }
    closeDialog = true;
    Utils.stopCursor(tasksShell);
    tasksShell.dispose();
  }

  /**
   * Der Wizzard wurde �ber den JobChain Dialog aufgerufen.
   * @param jobname
   */
  public void setJobname(Combo jobname) {
    this.jobname = jobname;
  }

  /**
   * Der Wizzard wurde f�r ein bestehende Job gestartet.
   * Beim verlassen der Wizzard ohne Speichern, muss der bestehende Job ohne �nderungen wieder zur�ckgesetz werden.
   * @param backUpJob
   */
  public void setBackUpJob(Element backUpJob, JobMainForm jobForm_) {
    if(backUpJob != null)
      jobBackUp = (Element)backUpJob.clone();
    if(jobForm_ != null)
      jobForm = jobForm_;
  }

  private void doFinish() {

    if(!checkTasks()) return;

    if(assistentType == Editor.JOB_WIZZARD) {                             
      jobForm.initForm();   
    } else {           
      JobsListener j = new JobsListener(dom, update);
      j.newImportJob(joblistener.getJob(), assistentType);       
    }

    if(Options.getPropertyBoolean("editor.job.show.wizard"))
      Utils.showClipboard(Messages.getString("assistent.finish") + "\n\n" + Utils.getElementAsString(joblistener.getJob()), tasksShell, false, null, false, null, true);


    if(jobname != null)
      jobname.setText(Utils.getAttributeValue("name",joblistener.getJob()))

    closeDialog = true;
    tasksShell.dispose();
  }
}
TOP

Related Classes of sos.scheduler.editor.conf.forms.JobAssistentTasksForm

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.