Example usage for org.eclipse.jface.dialogs MessageDialogWithToggle getToggleState

List of usage examples for org.eclipse.jface.dialogs MessageDialogWithToggle getToggleState

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialogWithToggle getToggleState.

Prototype

public boolean getToggleState() 

Source Link

Document

Returns the toggle state.

Usage

From source file:au.gov.ga.earthsci.bookmark.part.BookmarksController.java

License:Apache License

@Override
public boolean deleteBookmarkList(IBookmarkList list) {
    if (list == null || list == bookmarks.getDefaultList()) {
        return false;
    }/*from w  w  w  .  j ava  2 s . c o m*/

    if (preferences.askForListDeleteConfirmation()) {
        MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(
                Display.getDefault().getActiveShell(),
                Messages.BookmarksController_BookmarkListDeleteDialogTitle,
                Messages.BookmarksController_BookmarkListDeleteDialogMessage,
                Messages.BookmarksController_BookmarkListDeleteDialogToggleMessage,
                preferences.askForListDeleteConfirmation(), null, null);
        if (dialog.getReturnCode() != MessageDialog.OK) {
            return false;
        }

        preferences.setAskForListDeleteConfirmation(dialog.getToggleState());
    }

    return bookmarks.removeList(list);
}

From source file:au.gov.ga.earthsci.catalog.part.CatalogBrowserController.java

License:Apache License

private boolean isFullNodePathRequiredOnAdd() {
    if (preferences.getAddNodeStructureMode() != UserActionPreference.ASK) {
        return preferences.getAddNodeStructureMode() == UserActionPreference.ALWAYS;
    }// ww w. j  a v  a 2s.c  om

    MessageDialogWithToggle message = MessageDialogWithToggle.openYesNoQuestion(null,
            Messages.CatalogBrowserController_AddNodePathDialogTitle,
            Messages.CatalogBrowserController_AddNodePathDialogMessage,
            Messages.CatalogBrowserController_DialogDontAsk, false, null, null);

    UserActionPreference preference = (message.getReturnCode() == IDialogConstants.YES_ID)
            ? UserActionPreference.ALWAYS
            : UserActionPreference.NEVER;
    preferences.setAddNodeStructureMode(message.getToggleState() ? preference : UserActionPreference.ASK);

    return preference == UserActionPreference.ALWAYS;
}

From source file:au.gov.ga.earthsci.catalog.part.CatalogBrowserController.java

License:Apache License

private boolean isEmptyFolderDeletionRequiredOnRemoval() {
    if (preferences.getDeleteEmptyFoldersMode() != UserActionPreference.ASK) {
        return preferences.getDeleteEmptyFoldersMode() == UserActionPreference.ALWAYS;
    }// w w w  .j  av  a 2 s .  co m

    MessageDialogWithToggle message = MessageDialogWithToggle.openYesNoQuestion(null,
            Messages.CatalogBrowserController_DeleteEmptyFoldersDialogTitle,
            Messages.CatalogBrowserController_DeleteEmptyFoldersMessage,
            Messages.CatalogBrowserController_DialogDontAsk, false, null, null);

    UserActionPreference preference = (message.getReturnCode() == IDialogConstants.YES_ID)
            ? UserActionPreference.ALWAYS
            : UserActionPreference.NEVER;
    preferences.setDeleteEmptyFoldersMode(message.getToggleState() ? preference : UserActionPreference.ASK);

    return preference == UserActionPreference.ALWAYS;
}

From source file:be.ibridge.kettle.chef.Chef.java

License:LGPL

public boolean quitFile() {
    boolean exit = true;
    boolean showWarning = true;

    log.logDetailed(toString(), "Quit application."); //$NON-NLS-1$
    saveSettings();//from www.j  a  v a 2s .com
    if (jobMeta.hasChanged()) {
        MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_WARNING);
        mb.setMessage(Messages.getString("Chef.Dialog.FileChangedSaveFirst.Message")); //$NON-NLS-1$
        mb.setText(Messages.getString("Chef.Dialog.FileChangedSaveFirst.Title")); //$NON-NLS-1$
        int answer = mb.open();

        switch (answer) {
        case SWT.YES:
            saveFile();
            exit = true;
            showWarning = false;
            break;
        case SWT.NO:
            exit = true;
            showWarning = false;
            break;
        case SWT.CANCEL:
            exit = false;
            showWarning = false;
            break;
        }
    }

    // System.out.println("exit="+exit+", showWarning="+showWarning+", running="+spoonlog.isRunning()+", showExitWarning="+props.showExitWarning());

    // Show warning on exit when spoon is still running
    // Show warning on exit when a warning needs to be displayed, but only if we didn't ask to save before. (could have pressed cancel then!)
    // 
    if ((exit && cheflog.isRunning()) || (exit && showWarning && props.showExitWarning())) {
        String message = Messages.getString("Chef.Dialog.ExitApplicationAreYouSure.Message"); //$NON-NLS-1$
        if (cheflog.isRunning())
            message = Messages.getString("Chef.Dialog.ExitApplicationAreYouSure.MessageRunning"); //$NON-NLS-1$

        MessageDialogWithToggle md = new MessageDialogWithToggle(shell,
                Messages.getString("Chef.Dialog.ExitApplicationAreYouSure.Title"), //$NON-NLS-1$
                null, message, MessageDialog.WARNING,
                new String[] { Messages.getString("System.Button.Yes"), //$NON-NLS-1$
                        Messages.getString("System.Button.No") }, //$NON-NLS-1$
                1, Messages.getString("Chef.Dialog.ExitApplicationAreYouSure.Toggle"), //$NON-NLS-1$
                !props.showExitWarning());
        int idx = md.open();
        props.setExitWarningShown(!md.getToggleState());
        props.saveProps();

        if ((idx & 0xFF) == 1)
            exit = false; // No selected: don't exit!
        else
            exit = true;
    }

    if (exit)
        dispose();

    return exit;
}

From source file:be.ibridge.kettle.chef.Chef.java

License:LGPL

public boolean saveRepository(boolean ask_name) {
    log.logDetailed(toString(), "Save to repository..."); //$NON-NLS-1$
    if (rep != null) {
        boolean answer = true;
        boolean ask = ask_name;
        while (answer && (ask || jobMeta.getName() == null || jobMeta.getName().length() == 0)) {
            if (!ask) {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                mb.setMessage(Messages.getString("Chef.Dialog.GiveJobANameBeforeSaving.Message")); //$NON-NLS-1$
                mb.setText(Messages.getString("Chef.Dialog.GiveJobANameBeforeSaving.Title")); //$NON-NLS-1$
                mb.open();/*w ww.  j  ava  2  s. c  o  m*/
            }
            ask = false;
            answer = setJob();
        }

        if (answer && jobMeta.getName() != null && jobMeta.getName().length() > 0) {
            if (!rep.getUserInfo().isReadonly()) {
                boolean saved = false;
                int response = SWT.YES;
                if (jobMeta.showReplaceWarning(rep)) {
                    MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                    mb.setMessage(Messages.getString("Chef.Dialog.JobExistsOverwrite.Message1") //$NON-NLS-1$
                            + jobMeta.getName() + Messages.getString("Chef.Dialog.JobExistsOverwrite.Message2") //$NON-NLS-1$
                            + Const.CR + Messages.getString("Chef.Dialog.JobExistsOverwrite.Message3")); //$NON-NLS-1$
                    mb.setText(Messages.getString("Chef.Dialog.JobExistsOverwrite.Title")); //$NON-NLS-1$
                    response = mb.open();
                }

                if (response == SWT.YES) {
                    // Keep info on who & when this transformation was changed...
                    jobMeta.modifiedDate = new Value("MODIFIED_DATE", Value.VALUE_TYPE_DATE); //$NON-NLS-1$
                    jobMeta.modifiedDate.sysdate();
                    jobMeta.modifiedUser = rep.getUserInfo().getLogin();

                    JobSaveProgressDialog jspd = new JobSaveProgressDialog(shell, rep, jobMeta);
                    if (jspd.open()) {
                        if (!props.getSaveConfirmation()) {
                            MessageDialogWithToggle md = new MessageDialogWithToggle(shell,
                                    Messages.getString("Chef.Dialog.JobWasStoredInTheRepository.Title"), //$NON-NLS-1$
                                    null, Messages.getString("Chef.Dialog.JobWasStoredInTheRepository.Message"), //$NON-NLS-1$
                                    MessageDialog.QUESTION,
                                    new String[] { Messages.getString("System.Button.OK") }, //$NON-NLS-1$
                                    0, Messages.getString("Chef.Dialog.JobWasStoredInTheRepository.Toggle"), //$NON-NLS-1$
                                    props.getSaveConfirmation());
                            md.open();
                            props.setSaveConfirmation(md.getToggleState());
                        }

                        // Handle last opened files...
                        props.addLastFile(LastUsedFile.FILE_TYPE_JOB, jobMeta.getName(),
                                jobMeta.getDirectory().getPath(), true, rep.getName());
                        saveSettings();
                        addMenuLast();

                        setShellText();
                    }
                }
                return saved;
            } else {
                MessageBox mb = new MessageBox(shell, SWT.CLOSE | SWT.ICON_ERROR);
                mb.setMessage(
                        Messages.getString("Chef.Dialog.UserCanOnlyReadFromTheRepositoryJobNotSaved.Message")); //$NON-NLS-1$
                mb.setText(Messages.getString("Chef.Dialog.UserCanOnlyReadFromTheRepositoryJobNotSaved.Title")); //$NON-NLS-1$
                mb.open();
            }
        }
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(Messages.getString("Chef.Dialog.NoRepositoryConnectionAvailable.Message")); //$NON-NLS-1$
        mb.setText(Messages.getString("Chef.Dialog.NoRepositoryConnectionAvailable.Title")); //$NON-NLS-1$
        mb.open();
    }
    return false;
}

From source file:be.ibridge.kettle.chef.ChefGraph.java

License:LGPL

public ChefGraph(Composite par, final Spoon spoon, final JobMeta jobMeta) {
    super(par, SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_BACKGROUND);
    shell = par.getShell();/*w  w w  . j av a2 s .c om*/
    this.log = LogWriter.getInstance();
    this.spoon = spoon;
    this.canvas = this;
    this.jobMeta = jobMeta;

    newProps();

    selrect = null;
    hop_candidate = null;
    last_hop_split = null;

    selected_entries = null;
    selected_note = null;

    hori = getHorizontalBar();
    vert = getVerticalBar();

    hori.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            redraw();
        }
    });
    vert.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            redraw();
        }
    });
    hori.setThumb(100);
    vert.setThumb(100);

    hori.setVisible(true);
    vert.setVisible(true);

    setVisible(true);

    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            ChefGraph.this.paintControl(e);
        }
    });

    selected_entries = null;
    lastclick = null;

    addMouseListener(new MouseAdapter() {
        public void mouseDoubleClick(MouseEvent e) {
            clearSettings();

            Point real = screen2real(e.x, e.y);

            JobEntryCopy jobentry = jobMeta.getChefGraphEntry(real.x, real.y, iconsize);
            if (jobentry != null) {
                if (e.button == 1) {
                    editEntry(jobentry);
                } else // launch Chef or Spoon 
                {
                    launchStuff(jobentry);
                }
            } else {
                // Check if point lies on one of the many hop-lines...
                JobHopMeta online = findJobHop(real.x, real.y);
                if (online != null) {
                    // editJobHop(online);
                } else {
                    NotePadMeta ni = jobMeta.getNote(real.x, real.y);
                    if (ni != null) {
                        editNote(ni);
                    }
                }

            }
        }

        public void mouseDown(MouseEvent e) {
            clearSettings();

            last_button = e.button;
            Point real = screen2real(e.x, e.y);
            lastclick = new Point(real.x, real.y);

            // Clear the tooltip!
            setToolTipText(null);

            // Set the pop-up menu
            if (e.button == 3) {
                setMenu(real.x, real.y);
                return;
            }

            JobEntryCopy je = jobMeta.getChefGraphEntry(real.x, real.y, iconsize);
            if (je != null) {
                selected_entries = jobMeta.getSelectedEntries();
                selected_icon = je;
                // make sure this is correct!!!
                // When an icon is moved that is not selected, it gets selected too late.
                // It is not captured here, but in the mouseMoveListener...
                prev_locations = jobMeta.getSelectedLocations();

                Point p = je.getLocation();
                iconoffset = new Point(real.x - p.x, real.y - p.y);
            } else {
                // Dit we hit a note?
                NotePadMeta ni = jobMeta.getNote(real.x, real.y);
                if (ni != null && last_button == 1) {
                    selected_note = ni;
                    Point loc = ni.getLocation();
                    previous_note_location = new Point(loc.x, loc.y);
                    noteoffset = new Point(real.x - loc.x, real.y - loc.y);
                    // System.out.println("We hit a note!!");
                } else {
                    selrect = new Rectangle(real.x, real.y, 0, 0);
                }
            }
            redraw();
        }

        public void mouseUp(MouseEvent e) {
            boolean control = (e.stateMask & SWT.CONTROL) != 0;

            if (iconoffset == null)
                iconoffset = new Point(0, 0);
            Point real = screen2real(e.x, e.y);
            Point icon = new Point(real.x - iconoffset.x, real.y - iconoffset.y);

            // See if we need to add a hop...
            if (hop_candidate != null) {
                // hop doesn't already exist
                if (jobMeta.findJobHop(hop_candidate.from_entry, hop_candidate.to_entry) == null) {
                    if (!hop_candidate.from_entry.evaluates() && hop_candidate.from_entry.isUnconditional()) {
                        hop_candidate.setUnconditional();
                    } else {
                        hop_candidate.setConditional();
                        int nr = jobMeta.findNrNextChefGraphEntries(hop_candidate.from_entry);

                        // If there is one green link: make this one red! (or vice-versa)
                        if (nr == 1) {
                            JobEntryCopy jge = jobMeta.findNextChefGraphEntry(hop_candidate.from_entry, 0);
                            JobHopMeta other = jobMeta.findJobHop(hop_candidate.from_entry, jge);
                            if (other != null) {
                                hop_candidate.setEvaluation(!other.getEvaluation());
                            }
                        }
                    }

                    jobMeta.addJobHop(hop_candidate);
                    spoon.addUndoNew(jobMeta, new JobHopMeta[] { hop_candidate },
                            new int[] { jobMeta.indexOfJobHop(hop_candidate) });
                    spoon.refreshTree();
                }
                hop_candidate = null;
                selected_entries = null;
                last_button = 0;
                redraw();
            }

            // Did we select a region on the screen?  
            else if (selrect != null) {
                selrect.width = real.x - selrect.x;
                selrect.height = real.y - selrect.y;

                jobMeta.unselectAll();
                jobMeta.selectInRect(selrect);
                selrect = null;
                redraw();
            }

            // Clicked on an icon?
            //
            else if (selected_icon != null) {
                if (e.button == 1) {
                    if (lastclick.x == real.x && lastclick.y == real.y) {
                        // Flip selection when control is pressed!
                        if (control) {
                            selected_icon.flipSelected();
                        } else {
                            // Otherwise, select only the icon clicked on!
                            jobMeta.unselectAll();
                            selected_icon.setSelected(true);
                        }
                    } else // We moved around some items: store undo info...
                    if (selected_entries != null && prev_locations != null) {
                        int indexes[] = jobMeta.getEntryIndexes(selected_entries);
                        spoon.addUndoPosition(jobMeta, selected_entries, indexes, prev_locations,
                                jobMeta.getSelectedLocations());
                    }
                }

                // OK, we moved the step, did we move it across a hop?
                // If so, ask to split the hop!
                if (split_hop) {
                    JobHopMeta hi = findJobHop(icon.x + iconsize / 2, icon.y + iconsize / 2);
                    if (hi != null) {
                        int id = 0;
                        if (!spoon.props.getAutoSplit()) {
                            MessageDialogWithToggle md = new MessageDialogWithToggle(shell,
                                    Messages.getString("ChefGraph.Dialog.SplitHop.Title"), null,
                                    Messages.getString("ChefGraph.Dialog.SplitHop.Message") + Const.CR
                                            + hi.from_entry.getName() + " --> " + hi.to_entry.getName(),
                                    MessageDialog.QUESTION,
                                    new String[] { Messages.getString("System.Button.Yes"),
                                            Messages.getString("System.Button.No") },
                                    0, Messages.getString("ChefGraph.Dialog.SplitHop.Toggle"),
                                    spoon.props.getAutoSplit());
                            id = md.open();
                            spoon.props.setAutoSplit(md.getToggleState());
                        }

                        if ((id & 0xFF) == 0) {
                            JobHopMeta newhop1 = new JobHopMeta(hi.from_entry, selected_icon);
                            jobMeta.addJobHop(newhop1);
                            JobHopMeta newhop2 = new JobHopMeta(selected_icon, hi.to_entry);
                            jobMeta.addJobHop(newhop2);
                            if (!selected_icon.evaluates())
                                newhop2.setUnconditional();

                            spoon.addUndoNew(jobMeta,
                                    new JobHopMeta[] { (JobHopMeta) newhop1.clone(),
                                            (JobHopMeta) newhop2.clone() },
                                    new int[] { jobMeta.indexOfJobHop(newhop1),
                                            jobMeta.indexOfJobHop(newhop2) });
                            int idx = jobMeta.indexOfJobHop(hi);
                            spoon.addUndoDelete(jobMeta, new JobHopMeta[] { (JobHopMeta) hi.clone() },
                                    new int[] { idx });
                            jobMeta.removeJobHop(idx);
                            spoon.refreshTree();

                        }
                    }
                    split_hop = false;
                }

                selected_entries = null;
                redraw();
            }

            // Notes?
            else if (selected_note != null) {
                Point note = new Point(real.x - noteoffset.x, real.y - noteoffset.y);
                if (last_button == 1) {
                    if (lastclick.x != real.x || lastclick.y != real.y) {
                        int indexes[] = new int[] { jobMeta.indexOfNote(selected_note) };
                        spoon.addUndoPosition(jobMeta, new NotePadMeta[] { selected_note }, indexes,
                                new Point[] { previous_note_location }, new Point[] { note });
                    }
                }
                selected_note = null;
            }
        }
    });

    addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent e) {
            boolean shift = (e.stateMask & SWT.SHIFT) != 0;

            // Remember the last position of the mouse for paste with keyboard
            lastMove = new Point(e.x, e.y);

            if (iconoffset == null)
                iconoffset = new Point(0, 0);
            Point real = screen2real(e.x, e.y);
            Point icon = new Point(real.x - iconoffset.x, real.y - iconoffset.y);

            setToolTip(real.x, real.y);

            // First see if the icon we clicked on was selected.
            // If the icon was not selected, we should unselect all other icons,
            // selected and move only the one icon
            if (selected_icon != null && !selected_icon.isSelected()) {
                jobMeta.unselectAll();
                selected_icon.setSelected(true);
                selected_entries = new JobEntryCopy[] { selected_icon };
                prev_locations = new Point[] { selected_icon.getLocation() };
            }

            // Did we select a region...?
            if (selrect != null) {
                selrect.width = real.x - selrect.x;
                selrect.height = real.y - selrect.y;
                redraw();
            } else

            // Or just one entry on the screen?
            if (selected_entries != null) {
                if (last_button == 1 && !shift) {
                    /*
                     * One or more icons are selected and moved around...
                     * 
                     * new : new position of the ICON (not the mouse pointer)
                     * dx  : difference with previous position
                     */
                    int dx = icon.x - selected_icon.getLocation().x;
                    int dy = icon.y - selected_icon.getLocation().y;

                    JobHopMeta hi = findJobHop(icon.x + iconsize / 2, icon.y + iconsize / 2);
                    if (hi != null) {
                        //log.logBasic("MouseMove", "Split hop candidate B!");
                        if (!jobMeta.isEntryUsedInHops(selected_icon)) {
                            //log.logBasic("MouseMove", "Split hop candidate A!");
                            split_hop = true;
                            last_hop_split = hi;
                            hi.setSplit(true);
                        }
                    } else {
                        if (last_hop_split != null) {
                            last_hop_split.setSplit(false);
                            last_hop_split = null;
                            split_hop = false;
                        }
                    }

                    //
                    // One or more job entries are being moved around!
                    //
                    for (int i = 0; i < jobMeta.nrJobEntries(); i++) {
                        JobEntryCopy je = jobMeta.getJobEntry(i);
                        if (je.isSelected()) {
                            je.setLocation(je.getLocation().x + dx, je.getLocation().y + dy);

                        }
                    }
                    // selected_icon.setLocation(icon.x, icon.y);

                    redraw();
                } else
                //   The middle button perhaps?
                if (last_button == 2 || (last_button == 1 && shift)) {
                    JobEntryCopy si = jobMeta.getChefGraphEntry(real.x, real.y, iconsize);
                    if (si != null && !selected_icon.equals(si)) {
                        if (hop_candidate == null) {
                            hop_candidate = new JobHopMeta(selected_icon, si);
                            redraw();
                        }
                    } else {
                        if (hop_candidate != null) {
                            hop_candidate = null;
                            redraw();
                        }
                    }
                }
            } else
            // are we moving a note around? 
            if (selected_note != null) {
                if (last_button == 1) {
                    Point note = new Point(real.x - noteoffset.x, real.y - noteoffset.y);
                    selected_note.setLocation(note.x, note.y);
                    redraw();
                    //spoon.refreshGraph();  removed in 2.4.1 (SB: defect #4862)
                }
            }
        }
    });

    // Drag & Drop for steps
    Transfer[] ttypes = new Transfer[] { XMLTransfer.getInstance() };
    DropTarget ddTarget = new DropTarget(this, DND.DROP_MOVE);
    ddTarget.setTransfer(ttypes);
    ddTarget.addDropListener(new DropTargetListener() {
        public void dragEnter(DropTargetEvent event) {
            drop_candidate = getRealPosition(canvas, event.x, event.y);
            redraw();
        }

        public void dragLeave(DropTargetEvent event) {
            drop_candidate = null;
            redraw();
        }

        public void dragOperationChanged(DropTargetEvent event) {
        }

        public void dragOver(DropTargetEvent event) {
            drop_candidate = getRealPosition(canvas, event.x, event.y);
            redraw();
        }

        public void drop(DropTargetEvent event) {
            // no data to copy, indicate failure in event.detail 
            if (event.data == null) {
                event.detail = DND.DROP_NONE;
                return;
            }

            Point p = getRealPosition(canvas, event.x, event.y);

            try {
                DragAndDropContainer container = (DragAndDropContainer) event.data;
                String entry = container.getData();

                switch (container.getType()) {
                case DragAndDropContainer.TYPE_BASE_JOB_ENTRY: // Create a new Job Entry on the canvas
                {
                    JobEntryCopy jge = spoon.newJobEntry(jobMeta, entry, false);
                    if (jge != null) {
                        jge.setLocation(p.x, p.y);
                        jge.setDrawn();
                        redraw();
                    }
                }
                    break;
                case DragAndDropContainer.TYPE_JOB_ENTRY: // Drag existing one onto the canvas
                {
                    JobEntryCopy jge = jobMeta.findJobEntry(entry, 0, true);
                    if (jge != null) // Create duplicate of existing entry 
                    {
                        // There can be only 1 start!
                        if (jge.isStart() && jge.isDrawn()) {
                            showOnlyStartOnceMessage(shell);
                            return;
                        }

                        boolean jge_changed = false;

                        // For undo :
                        JobEntryCopy before = (JobEntryCopy) jge.clone_deep();

                        JobEntryCopy newjge = jge;
                        if (jge.isDrawn()) {
                            newjge = (JobEntryCopy) jge.clone();
                            if (newjge != null) {
                                // newjge.setEntry(jge.getEntry());
                                log.logDebug(toString(), "entry aft = " + ((Object) jge.getEntry()).toString()); //$NON-NLS-1$

                                newjge.setNr(jobMeta.findUnusedNr(newjge.getName()));

                                jobMeta.addJobEntry(newjge);
                                spoon.addUndoNew(jobMeta, new JobEntryCopy[] { newjge },
                                        new int[] { jobMeta.indexOfJobEntry(newjge) });
                            } else {
                                log.logDebug(toString(), "jge is not cloned!"); //$NON-NLS-1$
                            }
                        } else {
                            log.logDebug(toString(), jge.toString() + " is not drawn"); //$NON-NLS-1$
                            jge_changed = true;
                        }
                        newjge.setLocation(p.x, p.y);
                        newjge.setDrawn();
                        if (jge_changed) {
                            spoon.addUndoChange(jobMeta, new JobEntryCopy[] { before },
                                    new JobEntryCopy[] { newjge },
                                    new int[] { jobMeta.indexOfJobEntry(newjge) });
                        }
                        redraw();
                        spoon.refreshTree();
                        log.logBasic("DropTargetEvent", "DROP " + newjge.toString() + "!, type="
                                + JobEntryCopy.getTypeDesc(newjge.getType()));
                    } else {
                        log.logError(toString(), "Unknown job entry dropped onto the canvas.");
                    }
                }
                    break;
                default:
                    break;
                }
            } catch (Exception e) {
                new ErrorDialog(shell, Messages.getString("ChefGraph.Dialog.ErrorDroppingObject.Message"),
                        Messages.getString("Chefraph.Dialog.ErrorDroppingObject.Title"), e);
            }
        }

        public void dropAccept(DropTargetEvent event) {
            drop_candidate = null;
        }
    });

    // Keyboard shortcuts...
    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            // F2 --> rename Job entry
            if (e.keyCode == SWT.F2) {
                renameJobEntry();
            }

            if (e.character == 3) // CTRL-C
            {
                spoon.copyJobEntries(jobMeta, jobMeta.getSelectedEntries());
            }
            if (e.character == 22) // CTRL-V
            {
                String clipcontent = spoon.fromClipboard();
                if (clipcontent != null) {
                    if (lastMove != null) {
                        spoon.pasteXML(jobMeta, clipcontent, lastMove);
                    }
                }

                //spoon.pasteSteps( );
            }
            if (e.keyCode == SWT.ESC) {
                jobMeta.unselectAll();
                redraw();
            }
            // Delete
            if (e.keyCode == SWT.DEL) {
                JobEntryCopy copies[] = jobMeta.getSelectedEntries();
                if (copies != null && copies.length > 0) {
                    delSelected();
                }
            }
            // CTRL-UP : allignTop();
            if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.CONTROL) != 0) {
                alligntop();
            }
            // CTRL-DOWN : allignBottom();
            if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.CONTROL) != 0) {
                allignbottom();
            }
            // CTRL-LEFT : allignleft();
            if (e.keyCode == SWT.ARROW_LEFT && (e.stateMask & SWT.CONTROL) != 0) {
                allignleft();
            }
            // CTRL-RIGHT : allignRight();
            if (e.keyCode == SWT.ARROW_RIGHT && (e.stateMask & SWT.CONTROL) != 0) {
                allignright();
            }
            // ALT-RIGHT : distributeHorizontal();
            if (e.keyCode == SWT.ARROW_RIGHT && (e.stateMask & SWT.ALT) != 0) {
                distributehorizontal();
            }
            // ALT-UP : distributeVertical();
            if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.ALT) != 0) {
                distributevertical();
            }
            // ALT-HOME : snap to grid
            if (e.keyCode == SWT.HOME && (e.stateMask & SWT.ALT) != 0) {
                snaptogrid(Const.GRID_SIZE);
            }
        }
    });

    addKeyListener(spoon.defKeys);

    setBackground(GUIResource.getInstance().getColorBackground());

    setLayout(new FormLayout());
}

From source file:be.ibridge.kettle.chef.ChefLog.java

License:LGPL

public synchronized void startJob(Date replayDate) {
    if (job == null) // Not running, start the transformation...
    {//from  www  .jav  a 2  s  .c o m
        // Auto save feature...
        if (jobMeta.hasChanged()) {
            if (spoon.props.getAutoSave()) {
                log.logDetailed(toString(), Messages.getString("ChefLog.Log.AutoSaveFileBeforeRunning")); //$NON-NLS-1$
                System.out.println(Messages.getString("ChefLog.Log.AutoSaveFileBeforeRunning2")); //$NON-NLS-1$
                spoon.saveJobFile(jobMeta);
            } else {
                MessageDialogWithToggle md = new MessageDialogWithToggle(shell,
                        Messages.getString("ChefLog.Dialog.SaveChangedFile.Title"), //$NON-NLS-1$
                        null,
                        Messages.getString("ChefLog.Dialog.SaveChangedFile.Message") + Const.CR //$NON-NLS-1$
                                + Messages.getString("ChefLog.Dialog.SaveChangedFile.Message2") + Const.CR, //$NON-NLS-1$
                        MessageDialog.QUESTION,
                        new String[] { Messages.getString("System.Button.Yes"), //$NON-NLS-1$
                                Messages.getString("System.Button.No") }, //$NON-NLS-1$
                        0, Messages.getString("ChefLog.Dialog.SaveChangedFile.Toggle"), //$NON-NLS-1$
                        spoon.props.getAutoSave());
                int answer = md.open();
                if ((answer & 0xFF) == 0) {
                    spoon.saveJobFile(jobMeta);
                }
                spoon.props.setAutoSave(md.getToggleState());
            }
        }

        if (((jobMeta.getName() != null && spoon.rep != null) || // Repository available & name set
                (jobMeta.getFilename() != null && spoon.rep == null) // No repository & filename set
        ) && !jobMeta.hasChanged() // Didn't change
        ) {
            if (job == null || (job != null && job.isActive())) {
                try {
                    // TODO: clean up this awfull mess...
                    //
                    job = new Job(log, jobMeta.getName(), jobMeta.getFilename(), null);
                    job.open(spoon.rep, jobMeta.getFilename(), jobMeta.getName(),
                            jobMeta.getDirectory().getPath());
                    job.getJobMeta().setArguments(jobMeta.getArguments());

                    log.logMinimal(Chef.APP_NAME, Messages.getString("ChefLog.Log.StartingJob")); //$NON-NLS-1$
                    job.start();
                    // Link to the new jobTracker!
                    jobTracker = job.getJobTracker();
                    isRunning = true;
                } catch (KettleException e) {
                    new ErrorDialog(shell, Messages.getString("ChefLog.Dialog.CanNotOpenJob.Title"), //$NON-NLS-1$
                            Messages.getString("ChefLog.Dialog.CanNotOpenJob.Message"), e); //$NON-NLS-1$
                    job = null;
                }
            } else {
                MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                m.setText(Messages.getString("ChefLog.Dialog.JobIsAlreadyRunning.Title")); //$NON-NLS-1$
                m.setMessage(Messages.getString("ChefLog.Dialog.JobIsAlreadyRunning.Message")); //$NON-NLS-1$
                m.open();
            }
        } else {
            if (jobMeta.hasChanged()) {
                MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                m.setText(Messages.getString("ChefLog.Dialog.JobHasChangedSave.Title")); //$NON-NLS-1$
                m.setMessage(Messages.getString("ChefLog.Dialog.JobHasChangedSave.Message")); //$NON-NLS-1$
                m.open();
            } else if (spoon.rep != null && jobMeta.getName() == null) {
                MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                m.setText(Messages.getString("ChefLog.Dialog.PleaseGiveThisJobAName.Title")); //$NON-NLS-1$
                m.setMessage(Messages.getString("ChefLog.Dialog.PleaseGiveThisJobAName.Message")); //$NON-NLS-1$
                m.open();
            } else {
                MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
                m.setText(Messages.getString("ChefLog.Dialog.NoFilenameSaveYourJobFirst.Title")); //$NON-NLS-1$
                m.setMessage(Messages.getString("ChefLog.Dialog.NoFilenameSaveYourJobFirst.Message")); //$NON-NLS-1$
                m.open();
            }
        }
        enableFields();
    }
}

From source file:be.ibridge.kettle.job.JobMeta.java

License:LGPL

public void loadXML(Node jobnode, Repository rep) throws KettleXMLException {
    Props props = null;/* w  ww.j av a  2s. c o  m*/
    if (Props.isInitialized())
        props = Props.getInstance();

    try {
        // clear the jobs;
        clear();

        //
        // get job info:
        //
        name = XMLHandler.getTagValue(jobnode, "name"); //$NON-NLS-1$

        // Changed user/date
        modifiedUser = XMLHandler.getTagValue(jobnode, "modified_user"); //$NON-NLS-1$
        String modDate = XMLHandler.getTagValue(jobnode, "modified_date"); //$NON-NLS-1$
        if (modDate != null) {
            modifiedDate = new Value(STRING_MODIFIED_DATE, modDate);
            modifiedDate.setType(Value.VALUE_TYPE_DATE);
        }

        // Load the default list of databases
        // Read objects from the shared XML file & the repository
        try {
            sharedObjectsFile = XMLHandler.getTagValue(jobnode, "info", "shared_objects_file"); //$NON-NLS-1$ //$NON-NLS-2$
            readSharedObjects(rep);
        } catch (Exception e) {
            LogWriter.getInstance().logError(toString(),
                    Messages.getString("JobMeta.ErrorReadingSharedObjects.Message", e.toString())); // $NON-NLS-1$ //$NON-NLS-1$
            LogWriter.getInstance().logError(toString(), Const.getStackTracker(e));
        }

        // 
        // Read the database connections
        //
        int nr = XMLHandler.countNodes(jobnode, "connection"); //$NON-NLS-1$
        for (int i = 0; i < nr; i++) {
            Node dbnode = XMLHandler.getSubNodeByNr(jobnode, "connection", i); //$NON-NLS-1$
            DatabaseMeta dbcon = new DatabaseMeta(dbnode);

            DatabaseMeta exist = findDatabase(dbcon.getName());
            if (exist == null) {
                addDatabase(dbcon);
            } else {
                boolean askOverwrite = Props.isInitialized() ? props.askAboutReplacingDatabaseConnections()
                        : false;
                boolean overwrite = Props.isInitialized() ? props.replaceExistingDatabaseConnections() : true;
                if (askOverwrite) {
                    // That means that we have a Display variable set in Props...
                    if (props.getDisplay() != null) {
                        Shell shell = props.getDisplay().getActiveShell();

                        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, "Warning", null,
                                Messages.getString("JobMeta.Dialog.ConnectionExistsOverWrite.Message", //$NON-NLS-1$
                                        dbcon.getName()) //$NON-NLS-2$
                                , MessageDialog.WARNING, new String[] { Messages.getString("System.Button.Yes"), //$NON-NLS-1$ 
                                        Messages.getString("System.Button.No") }, //$NON-NLS-1$
                                1,
                                Messages.getString(
                                        "JobMeta.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage"), //$NON-NLS-1$
                                !props.askAboutReplacingDatabaseConnections());
                        int idx = md.open();
                        props.setAskAboutReplacingDatabaseConnections(!md.getToggleState());
                        overwrite = ((idx & 0xFF) == 0); // Yes means: overwrite
                    }
                }

                if (overwrite) {
                    int idx = indexOfDatabase(exist);
                    removeDatabase(idx);
                    addDatabase(idx, dbcon);
                }
            }
        }

        /*
         * Get the log database connection & log table
         */
        String logcon = XMLHandler.getTagValue(jobnode, "logconnection"); //$NON-NLS-1$
        logconnection = findDatabase(logcon);
        logTable = XMLHandler.getTagValue(jobnode, "logtable"); //$NON-NLS-1$

        useBatchId = "Y".equalsIgnoreCase(XMLHandler.getTagValue(jobnode, "use_batchid")); //$NON-NLS-1$ //$NON-NLS-2$
        batchIdPassed = "Y".equalsIgnoreCase(XMLHandler.getTagValue(jobnode, "pass_batchid")); //$NON-NLS-1$ //$NON-NLS-2$
        logfieldUsed = "Y".equalsIgnoreCase(XMLHandler.getTagValue(jobnode, "use_logfield")); //$NON-NLS-1$ //$NON-NLS-2$

        /*
         * read the job entries...
         */
        Node entriesnode = XMLHandler.getSubNode(jobnode, "entries"); //$NON-NLS-1$
        int tr = XMLHandler.countNodes(entriesnode, "entry"); //$NON-NLS-1$
        for (int i = 0; i < tr; i++) {
            Node entrynode = XMLHandler.getSubNodeByNr(entriesnode, "entry", i); //$NON-NLS-1$
            // System.out.println("Reading entry:\n"+entrynode);

            JobEntryCopy je = new JobEntryCopy(entrynode, databases, rep);
            JobEntryCopy prev = findJobEntry(je.getName(), 0, true);
            if (prev != null) {
                if (je.getNr() == 0) // See if the #0 already exists!
                {
                    // Replace previous version with this one: remove it first
                    int idx = indexOfJobEntry(prev);
                    removeJobEntry(idx);
                } else if (je.getNr() > 0) // Use previously defined JobEntry info!
                {
                    je.setEntry(prev.getEntry());

                    // See if entry already exists...
                    prev = findJobEntry(je.getName(), je.getNr(), true);
                    if (prev != null) // remove the old one!
                    {
                        int idx = indexOfJobEntry(prev);
                        removeJobEntry(idx);
                    }
                }
            }
            // Add the JobEntryCopy...
            addJobEntry(je);
        }

        Node hopsnode = XMLHandler.getSubNode(jobnode, "hops"); //$NON-NLS-1$
        int ho = XMLHandler.countNodes(hopsnode, "hop"); //$NON-NLS-1$
        for (int i = 0; i < ho; i++) {
            Node hopnode = XMLHandler.getSubNodeByNr(hopsnode, "hop", i); //$NON-NLS-1$
            JobHopMeta hi = new JobHopMeta(hopnode, this);
            jobhops.add(hi);
        }

        // Read the notes...
        Node notepadsnode = XMLHandler.getSubNode(jobnode, "notepads"); //$NON-NLS-1$
        int nrnotes = XMLHandler.countNodes(notepadsnode, "notepad"); //$NON-NLS-1$
        for (int i = 0; i < nrnotes; i++) {
            Node notepadnode = XMLHandler.getSubNodeByNr(notepadsnode, "notepad", i); //$NON-NLS-1$
            NotePadMeta ni = new NotePadMeta(notepadnode);
            notes.add(ni);
        }

        // Do we have the special entries?
        // if (findJobEntry(STRING_SPECIAL_START, 0, true) == null) addJobEntry(JobMeta.createStartEntry()); // TODO: remove this
        // if (findJobEntry(STRING_SPECIAL_DUMMY, 0, true) == null) addJobEntry(JobMeta.createDummyEntry()); // TODO: remove this

        clearChanged();
    } catch (Exception e) {
        throw new KettleXMLException(Messages.getString("JobMeta.Exception.UnableToLoadJobFromXMLNode"), e); //$NON-NLS-1$
    } finally {
        setInternalKettleVariables();
    }
}

From source file:be.ibridge.kettle.spoon.Spoon.java

License:LGPL

public void verifyCopyDistribute(TransMeta transMeta, StepMeta fr) {
    int nrNextSteps = transMeta.findNrNextSteps(fr);

    // don't show it for 3 or more hops, by then you should have had the message
    if (nrNextSteps == 2) {
        boolean distributes = false;

        if (props.showCopyOrDistributeWarning()) {
            MessageDialogWithToggle md = new MessageDialogWithToggle(shell,
                    Messages.getString("System.Warning"), //"Warning!" 
                    null,//from  w ww  .j  av  a2  s  .  c  om
                    Messages.getString("Spoon.Dialog.CopyOrDistribute.Message", fr.getName(),
                            Integer.toString(nrNextSteps)),
                    MessageDialog.WARNING,
                    new String[] { Messages.getString("Spoon.Dialog.CopyOrDistribute.Copy"),
                            Messages.getString("Spoon.Dialog.CopyOrDistribute.Distribute") }, //"Copy Distribute 
                    0, Messages.getString("Spoon.Message.Warning.NotShowWarning"), //"Please, don't show this warning anymore."
                    !props.showCopyOrDistributeWarning());
            int idx = md.open();
            props.setShowCopyOrDistributeWarning(!md.getToggleState());
            props.saveProps();

            distributes = (idx & 0xFF) == 1;
        }

        if (distributes) {
            fr.setDistributes(true);
        } else {
            fr.setDistributes(false);
        }

        refreshTree();
        refreshGraph();
    }
}

From source file:be.ibridge.kettle.spoon.Spoon.java

License:LGPL

public boolean quitFile() {
    log.logDetailed(toString(), Messages.getString("Spoon.Log.QuitApplication"));//"Quit application."

    boolean exit = true;

    saveSettings();//from w  w w. j a v  a 2  s. co m

    if (props.showExitWarning()) {
        MessageDialogWithToggle md = new MessageDialogWithToggle(shell, Messages.getString("System.Warning"), //"Warning!" 
                null, Messages.getString("Spoon.Message.Warning.PromptExit"), // Are you sure you want to exit?
                MessageDialog.WARNING,
                new String[] { Messages.getString("Spoon.Message.Warning.Yes"),
                        Messages.getString("Spoon.Message.Warning.No") }, //"Yes", "No" 
                1, Messages.getString("Spoon.Message.Warning.NotShowWarning"), //"Please, don't show this warning anymore."
                !props.showExitWarning());
        int idx = md.open();
        props.setExitWarningShown(!md.getToggleState());
        props.saveProps();
        if ((idx & 0xFF) == 1)
            return false; // No selected: don't exit!
    }

    // Check all tabs to see if we can close them...
    List list = new ArrayList();
    list.addAll(tabMap.values());

    for (Iterator iter = list.iterator(); iter.hasNext() && exit;) {
        TabMapEntry mapEntry = (TabMapEntry) iter.next();
        TabItemInterface itemInterface = mapEntry.getObject();

        if (!itemInterface.canBeClosed()) {
            // Show the tab
            tabfolder.setSelection(mapEntry.getTabItem());

            // Unsaved work that needs to changes to be applied?
            //
            int reply = itemInterface.showChangedWarning();
            if (reply == SWT.YES) {
                exit = itemInterface.applyChanges();
            } else {
                if (reply == SWT.CANCEL) {
                    exit = false;
                } else // SWT.NO
                {
                    exit = true;
                }
            }

            /*
            if (mapEntry.getObject() instanceof SpoonGraph)
            {
            TransMeta transMeta = (TransMeta) mapEntry.getObject().getManagedObject();
            if (transMeta.hasChanged())
            {
                // Show the transformation in question
                //
                tabfolder.setSelection( mapEntry.getTabItem() );
                        
                // Ask if we should save it before closing...
                MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_WARNING );
                mb.setMessage(Messages.getString("Spoon.Dialog.SaveChangedFile.Message", makeGraphTabName(transMeta)));//"File has changed!  Do you want to save first?"
                mb.setText(Messages.getString("Spoon.Dialog.SaveChangedFile.Title"));//"Warning!"
                int answer = mb.open();
                    
                switch(answer)
                {
                case SWT.YES: exit=saveFile(transMeta); break;
                case SWT.NO:  exit=true; break;
                case SWT.CANCEL: 
                    exit=false;
                    break;
                }
            }
            }
            // A running transformation?
            //
            if (mapEntry.getObject() instanceof SpoonLog)
            {
            SpoonLog spoonLog = (SpoonLog) mapEntry.getObject();
            if (spoonLog.isRunning())
            {
                        
                if (reply==SWT.NO) exit=false; // No selected: don't exit!
            }
            }
            */

        }
    }

    if (exit) // we have asked about it all and we're still here.  Now close all the tabs, stop the running transformations
    {
        for (Iterator iter = list.iterator(); iter.hasNext() && exit;) {
            TabMapEntry mapEntry = (TabMapEntry) iter.next();

            if (!mapEntry.getObject().canBeClosed()) {
                // Unsaved transformation?
                //
                if (mapEntry.getObject() instanceof SpoonGraph) {
                    TransMeta transMeta = (TransMeta) mapEntry.getObject().getManagedObject();
                    if (transMeta.hasChanged()) {
                        mapEntry.getTabItem().dispose();
                    }
                }
                // A running transformation?
                //
                if (mapEntry.getObject() instanceof SpoonLog) {
                    SpoonLog spoonLog = (SpoonLog) mapEntry.getObject();
                    if (spoonLog.isRunning()) {
                        spoonLog.stop();
                        mapEntry.getTabItem().dispose();
                    }
                }
            }
        }
    }

    if (exit)
        dispose();

    return exit;
}