List of usage examples for org.eclipse.jface.dialogs MessageDialog QUESTION
int QUESTION
To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.
Click Source Link
From source file:ac.soton.fmusim.components.ui.actions.DeleteDiagramAction.java
License:Open Source License
@Override public void run() { if (!(site.getStructuredViewer().getSelection().isEmpty())) { IStructuredSelection ssel = (IStructuredSelection) site.getStructuredViewer().getSelection(); Object element = ssel.getFirstElement(); // TODO: add support for multiple files if (element instanceof IAdaptable) { View view = (View) ((IAdaptable) element).getAdapter(View.class); Resource resource = view.eResource(); if (resource != null && resource.isLoaded()) { IFile file = WorkspaceSynchronizer.getFile(resource); MessageDialog dialog = new MessageDialog(site.getViewSite().getShell(), "Confirm Diagram Delete", null, "Are you sure you want to delete the diagram file '" + file.getName() + "' from the project '" + file.getParent().getName() + "' ?", MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); if (dialog.open() == 0) { Resource domResource = view.getElement().eResource(); try { closeOpenedEditor(file); file.delete(false, false, new NullProgressMonitor()); WorkspaceSynchronizer.getFile(domResource).delete(false, false, new NullProgressMonitor()); } catch (PartInitException e) { e.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); }// ww w.j a v a 2s . com } } } } // MULTIPLE FILES HANDLING (from Systerel's ActionCollection) // // // Putting the selection into a set which does not contains any pair // // of parent and child // Collection<IRodinElement> set = new ArrayList<IRodinElement>(); // // IStructuredSelection ssel = (IStructuredSelection) site.getStructuredViewer().getSelection(); // // for (Iterator<?> it = ssel.iterator(); it.hasNext();) { // final Object obj = it.next(); // if (!(obj instanceof IRodinElement)) { // continue; // } // IRodinElement elem = (IRodinElement) obj; // if (elem.isRoot()) { // elem = elem.getParent(); // } // set = UIUtils.addToTreeSet(set, elem); // } // // int answer = YesToAllMessageDialog.YES; // for (IRodinElement element : set) { // if (element instanceof IRodinFile) { // if (answer != YesToAllMessageDialog.YES_TO_ALL) { // answer = YesToAllMessageDialog.openYesNoToAllQuestion( // site.getViewSite().getShell(), // "Confirm File Delete", // "Are you sure you want to delete file '" // + ((IRodinFile) element) // .getElementName() // + "' in project '" // + element.getParent().getElementName() // + "' ?"); // } // if (answer == YesToAllMessageDialog.NO_TO_ALL) // break; // // if (answer != YesToAllMessageDialog.NO) { // try { // closeOpenedEditor((IRodinFile) element); // ((IRodinFile) element).delete(true, // new NullProgressMonitor()); // } catch (PartInitException e) { // MessageDialog.openError(null, "Error", "Could not delete file"); // } catch (RodinDBException e) { // MessageDialog.openError(null, "Error", "Could not delete file"); // } // } // } // } }
From source file:ac.soton.multisim.ui.actions.DeleteDiagramAction.java
License:Open Source License
@Override public void run() { if (!(site.getStructuredViewer().getSelection().isEmpty())) { IStructuredSelection ssel = (IStructuredSelection) site.getStructuredViewer().getSelection(); Object element = ssel.getFirstElement(); if (element instanceof IAdaptable) { View view = (View) ((IAdaptable) element).getAdapter(View.class); Resource resource = view.eResource(); if (resource != null && resource.isLoaded()) { IFile file = WorkspaceSynchronizer.getFile(resource); MessageDialog dialog = new MessageDialog(site.getViewSite().getShell(), "Confirm Diagram Delete", null, "Are you sure you want to delete the diagram file '" + file.getName() + "' from the project '" + file.getParent().getName() + "' ?", MessageDialog.QUESTION, new String[] { "Yes", "No" }, 0); if (dialog.open() == 0) { Resource domResource = view.getElement().eResource(); try { closeOpenedEditor(file); file.delete(false, false, new NullProgressMonitor()); WorkspaceSynchronizer.getFile(domResource).delete(false, false, new NullProgressMonitor()); } catch (PartInitException e) { e.printStackTrace(); } catch (CoreException e) { e.printStackTrace(); }/*from w ww .ja v a2s . c om*/ } } } } }
From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.wizard.clazz.NewHtmlTemplateWizard.java
License:Open Source License
@Override protected IFile createFile() { IPath path;/*from w ww . ja v a2 s. c om*/ IPackageFragment fragment = getDomainClass().getPackageFragment(); if (fragment != null) { String cuName = getDomainClass().getName() + JavaFXUIPlugin.FILEEXTENSION_HTML_TEMPLATE; path = fragment.getPath().append(cuName); } else { String cuName = getDomainClass().getName() + JavaFXUIPlugin.FILEEXTENSION_HTML_TEMPLATE; IFolder p = (IFolder) getDomainClass().getFragmentRoot().getResource(); path = p.getLocation().append(cuName); } // If the path already exists then confirm overwrite. IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); if (file.exists()) { String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; String question = NLS.bind(IDEWorkbenchMessages.SaveAsDialog_overwriteQuestion, path.toString()); MessageDialog d = new MessageDialog(getShell(), IDEWorkbenchMessages.Question, null, question, MessageDialog.QUESTION, buttons, 0) { protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; int overwrite = d.open(); switch (overwrite) { case 0: // Yes break; case 1: // No return null; case 2: // Cancel default: return null; } } return file; }
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 w w. j av a 2 s . co 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();/*from w ww . ja v a2s . co m*/ 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... {/* w w w . j a v a2 s .com*/ // 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.spoon.Spoon.java
License:LGPL
public boolean saveTransRepository(TransMeta transMeta, boolean ask_name) { log.logDetailed(toString(), Messages.getString("Spoon.Log.SaveToRepository"));//"Save to repository..." if (rep != null) { boolean answer = true; boolean ask = ask_name; while (answer && (ask || Const.isEmpty(transMeta.getName()))) { if (!ask) { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING); mb.setMessage(Messages.getString("Spoon.Dialog.PromptTransformationName.Message"));//"Please give this transformation a name before saving it in the database." mb.setText(Messages.getString("Spoon.Dialog.PromptTransformationName.Title"));//"Transformation has no name." mb.open();// w w w .j ava2 s . com } ask = false; answer = editTransformationProperties(transMeta); } if (answer && !Const.isEmpty(transMeta.getName())) { if (!rep.getUserInfo().isReadonly()) { int response = SWT.YES; if (transMeta.showReplaceWarning(rep)) { MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION); mb.setMessage(Messages.getString("Spoon.Dialog.PromptOverwriteTransformation.Message", transMeta.getName(), Const.CR));//"There already is a transformation called ["+transMeta.getName()+"] in the repository."+Const.CR+"Do you want to overwrite the transformation?" mb.setText(Messages.getString("Spoon.Dialog.PromptOverwriteTransformation.Title"));//"Overwrite?" response = mb.open(); } boolean saved = false; if (response == SWT.YES) { shell.setCursor(cursor_hourglass); // Keep info on who & when this transformation was changed... transMeta.setModifiedDate(new Value("MODIFIED_DATE", Value.VALUE_TYPE_DATE)); transMeta.getModifiedDate().sysdate(); transMeta.setModifiedUser(rep.getUserInfo().getLogin()); TransSaveProgressDialog tspd = new TransSaveProgressDialog(shell, rep, transMeta); if (tspd.open()) { saved = true; if (!props.getSaveConfirmation()) { MessageDialogWithToggle md = new MessageDialogWithToggle(shell, Messages.getString("Spoon.Message.Warning.SaveOK"), //"Save OK!" null, Messages.getString("Spoon.Message.Warning.TransformationWasStored"), //"This transformation was stored in repository" MessageDialog.QUESTION, new String[] { Messages.getString("Spoon.Message.Warning.OK") }, //"OK!" 0, Messages.getString("Spoon.Message.Warning.NotShowThisMessage"), //"Don't show this message again." props.getSaveConfirmation()); md.open(); props.setSaveConfirmation(md.getToggleState()); } // Handle last opened files... props.addLastFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, transMeta.getName(), transMeta.getDirectory().getPath(), true, getRepositoryName()); saveSettings(); addMenuLast(); setShellText(); } shell.setCursor(null); } return saved; } else { MessageBox mb = new MessageBox(shell, SWT.CLOSE | SWT.ICON_ERROR); mb.setMessage(Messages.getString("Spoon.Dialog.OnlyreadRepository.Message"));//"Sorry, the user you're logged on with, can only read from the repository" mb.setText(Messages.getString("Spoon.Dialog.OnlyreadRepository.Title"));//"Transformation not saved!" mb.open(); } } } else { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); mb.setMessage(Messages.getString("Spoon.Dialog.NoRepositoryConnection.Message"));//"There is no repository connection available." mb.setText(Messages.getString("Spoon.Dialog.NoRepositoryConnection.Title"));//"No repository available." mb.open(); } return false; }
From source file:be.ibridge.kettle.spoon.Spoon.java
License:LGPL
public boolean saveJobRepository(JobMeta jobMeta, 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("Spoon.Dialog.GiveJobANameBeforeSaving.Message")); //$NON-NLS-1$ mb.setText(Messages.getString("Spoon.Dialog.GiveJobANameBeforeSaving.Title")); //$NON-NLS-1$ mb.open();/*from ww w. j a va 2 s .c o m*/ } ask = false; answer = editJobProperties(jobMeta); } 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("'" + jobMeta.getName() + "'" + Const.CR + Const.CR //$NON-NLS-1$//$NON-NLS-2$ + Messages.getString("Spoon.Dialog.FileExistsOverWrite.Message")); //$NON-NLS-1$ mb.setText(Messages.getString("Spoon.Dialog.FileExistsOverWrite.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("Spoon.Dialog.JobWasStoredInTheRepository.Title"), //$NON-NLS-1$ null, Messages.getString("Spoon.Dialog.JobWasStoredInTheRepository.Message"), //$NON-NLS-1$ MessageDialog.QUESTION, new String[] { Messages.getString("System.Button.OK") }, //$NON-NLS-1$ 0, Messages.getString("Spoon.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(); saved = true; } } return saved; } else { MessageBox mb = new MessageBox(shell, SWT.CLOSE | SWT.ICON_ERROR); mb.setMessage( Messages.getString("Spoon.Dialog.UserCanOnlyReadFromTheRepositoryJobNotSaved.Message")); //$NON-NLS-1$ mb.setText( Messages.getString("Spoon.Dialog.UserCanOnlyReadFromTheRepositoryJobNotSaved.Title")); //$NON-NLS-1$ mb.open(); } } } else { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); mb.setMessage(Messages.getString("Spoon.Dialog.NoRepositoryConnectionAvailable.Message")); //$NON-NLS-1$ mb.setText(Messages.getString("Spoon.Dialog.NoRepositoryConnectionAvailable.Title")); //$NON-NLS-1$ mb.open(); } return false; }
From source file:be.ibridge.kettle.spoon.SpoonGraph.java
License:LGPL
public SpoonGraph(Composite parent, final Spoon spoon, final TransMeta transMeta) { super(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_BACKGROUND); this.shell = parent.getShell(); this.spoon = spoon; this.transMeta = transMeta; canvas = this; iconsize = spoon.props.getIconSize(); clearSettings();// ww w . j av a 2s. c o m remarks = new ArrayList(); impact = new ArrayList(); impactFinished = false; 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); newProps(); canvas.setBackground(GUIResource.getInstance().getColorBackground()); addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { if (!spoon.isStopped()) SpoonGraph.this.paintControl(e); } }); selected_steps = null; lastclick = null; addKeyListener(spoon.modKeys); /* * Handle the mouse... */ addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent e) { clearSettings(); Point real = screen2real(e.x, e.y); StepMeta stepMeta = transMeta.getStep(real.x, real.y, iconsize); if (stepMeta != null) { if (e.button == 1) editStep(stepMeta); else editDescription(stepMeta); } else { // Check if point lies on one of the many hop-lines... TransHopMeta online = findHop(real.x, real.y); if (online != null) { editHop(online); } else { NotePadMeta ni = transMeta.getNote(real.x, real.y); if (ni != null) { selected_note = null; editNote(ni); } } } } public void mouseDown(MouseEvent e) { clearSettings(); boolean alt = (e.stateMask & SWT.ALT) != 0; boolean control = (e.stateMask & SWT.CONTROL) != 0; 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; } // Did we click on a step? StepMeta stepMeta = transMeta.getStep(real.x, real.y, iconsize); if (stepMeta != null) { // ALT-Click: edit error handling if (e.button == 1 && alt && stepMeta.supportsErrorHandling()) { spoon.editStepErrorHandling(transMeta, stepMeta); return; } selected_steps = transMeta.getSelectedSteps(); selected_step = stepMeta; // // When an icon is moved that is not selected, it gets // selected too late. // It is not captured here, but in the mouseMoveListener... previous_step_locations = transMeta.getSelectedStepLocations(); Point p = stepMeta.getLocation(); iconoffset = new Point(real.x - p.x, real.y - p.y); } else { // Dit we hit a note? NotePadMeta ni = transMeta.getNote(real.x, real.y); if (ni != null && last_button == 1) { selected_notes = transMeta.getSelectedNotes(); selected_note = ni; Point loc = ni.getLocation(); previous_note_locations = transMeta.getSelectedNoteLocations(); noteoffset = new Point(real.x - loc.x, real.y - loc.y); } else { if (!control) 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); // Quick new hop option? (drag from one step to another) // if (candidate != null) { if (transMeta.findTransHop(candidate) == null) { transMeta.addTransHop(candidate); spoon.refreshTree(); if (transMeta.hasLoop(candidate.getFromStep())) { MessageBox mb = new MessageBox(shell, SWT.YES | SWT.ICON_WARNING); mb.setMessage(Messages.getString("SpoonGraph.Dialog.HopCausesLoop.Message")); //$NON-NLS-1$ mb.setText(Messages.getString("SpoonGraph.Dialog.HopCausesLoop.Title")); //$NON-NLS-1$ mb.open(); int idx = transMeta.indexOfTransHop(candidate); transMeta.removeTransHop(idx); spoon.refreshTree(); } else { spoon.addUndoNew(transMeta, new TransHopMeta[] { candidate }, new int[] { transMeta.indexOfTransHop(candidate) }); } spoon.verifyCopyDistribute(transMeta, candidate.getFromStep()); } candidate = null; selected_steps = null; last_button = 0; redraw(); } // Did we select a region on the screen? Mark steps in region as // selected // else if (selrect != null) { selrect.width = real.x - selrect.x; selrect.height = real.y - selrect.y; transMeta.unselectAll(); transMeta.selectInRect(selrect); selrect = null; redraw(); } // Clicked on an icon? // else if (selected_step != null) { if (e.button == 1) { Point realclick = screen2real(e.x, e.y); if (lastclick.x == realclick.x && lastclick.y == realclick.y) { // Flip selection when control is pressed! if (control) { selected_step.flipSelected(); } else { // Otherwise, select only the icon clicked on! transMeta.unselectAll(); selected_step.setSelected(true); } } else { // Find out which Steps & Notes are selected selected_steps = transMeta.getSelectedSteps(); selected_notes = transMeta.getSelectedNotes(); // We moved around some items: store undo info... boolean also = false; if (selected_notes != null && previous_note_locations != null) { int indexes[] = transMeta.getNoteIndexes(selected_notes); addUndoPosition(selected_notes, indexes, previous_note_locations, transMeta.getSelectedNoteLocations(), also); also = selected_steps != null && selected_steps.length > 0; } if (selected_steps != null && previous_step_locations != null) { int indexes[] = transMeta.getStepIndexes(selected_steps); addUndoPosition(selected_steps, indexes, previous_step_locations, transMeta.getSelectedStepLocations(), also); } } } // OK, we moved the step, did we move it across a hop? // If so, ask to split the hop! if (split_hop) { TransHopMeta hi = findHop(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("SpoonGraph.Dialog.SplitHop.Title"), null, //$NON-NLS-1$ Messages.getString("SpoonGraph.Dialog.SplitHop.Message") + Const.CR //$NON-NLS-1$ + hi.toString(), MessageDialog.QUESTION, new String[] { Messages.getString("System.Button.Yes"), //$NON-NLS-1$ Messages.getString("System.Button.No") }, //$NON-NLS-1$ 0, Messages.getString("SpoonGraph.Dialog.Option.SplitHop.DoNotAskAgain"), //$NON-NLS-1$ spoon.props.getAutoSplit()); id = md.open(); spoon.props.setAutoSplit(md.getToggleState()); } if ((id & 0xFF) == 0) // Means: "Yes" button clicked! { TransHopMeta newhop1 = new TransHopMeta(hi.getFromStep(), selected_step); transMeta.addTransHop(newhop1); spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop1 }, new int[] { transMeta.indexOfTransHop(newhop1) }, true); TransHopMeta newhop2 = new TransHopMeta(selected_step, hi.getToStep()); transMeta.addTransHop(newhop2); spoon.addUndoNew(transMeta, new TransHopMeta[] { newhop2 }, new int[] { transMeta.indexOfTransHop(newhop2) }, true); int idx = transMeta.indexOfTransHop(hi); spoon.addUndoDelete(transMeta, new TransHopMeta[] { hi }, new int[] { idx }, true); transMeta.removeTransHop(idx); spoon.refreshTree(); } } split_hop = false; } selected_steps = null; selected_notes = null; selected_step = null; selected_note = null; redraw(); } // Notes? else if (selected_note != null) { if (e.button == 1) { if (lastclick.x == e.x && lastclick.y == e.y) { // Flip selection when control is pressed! if (control) { selected_note.flipSelected(); } else { // Otherwise, select only the note clicked on! transMeta.unselectAll(); selected_note.setSelected(true); } } else { // Find out which Steps & Notes are selected selected_steps = transMeta.getSelectedSteps(); selected_notes = transMeta.getSelectedNotes(); // We moved around some items: store undo info... boolean also = false; if (selected_notes != null && previous_note_locations != null) { int indexes[] = transMeta.getNoteIndexes(selected_notes); addUndoPosition(selected_notes, indexes, previous_note_locations, transMeta.getSelectedNoteLocations(), also); also = selected_steps != null && selected_steps.length > 0; } if (selected_steps != null && previous_step_locations != null) { int indexes[] = transMeta.getStepIndexes(selected_steps); addUndoPosition(selected_steps, indexes, previous_step_locations, transMeta.getSelectedStepLocations(), also); } } } selected_notes = null; selected_steps = null; selected_step = null; 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); Point real = screen2real(e.x, e.y); if (iconoffset == null) iconoffset = new Point(0, 0); Point icon = new Point(real.x - iconoffset.x, real.y - iconoffset.y); if (noteoffset == null) noteoffset = new Point(0, 0); Point note = new Point(real.x - noteoffset.x, real.y - noteoffset.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_step != null && !selected_step.isSelected()) { // System.out.println("STEPS: Unselected all"); transMeta.unselectAll(); selected_step.setSelected(true); selected_steps = new StepMeta[] { selected_step }; previous_step_locations = new Point[] { selected_step.getLocation() }; } if (selected_note != null && !selected_note.isSelected()) { // System.out.println("NOTES: Unselected all"); transMeta.unselectAll(); selected_note.setSelected(true); selected_notes = new NotePadMeta[] { selected_note }; previous_note_locations = new Point[] { selected_note.getLocation() }; } // Did we select a region...? if (selrect != null) { selrect.width = real.x - selrect.x; selrect.height = real.y - selrect.y; redraw(); } // Move around steps & notes else if (selected_step != 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_step.getLocation().x; int dy = icon.y - selected_step.getLocation().y; // See if we have a hop-split candidate // TransHopMeta hi = findHop(icon.x + iconsize / 2, icon.y + iconsize / 2); if (hi != null) { if (!hi.getFromStep().equals(selected_step) && !hi.getToStep().equals(selected_step)) { split_hop = true; last_hop_split = hi; hi.split = true; } } else { if (last_hop_split != null) { last_hop_split.split = false; last_hop_split = null; split_hop = false; } } selected_notes = transMeta.getSelectedNotes(); selected_steps = transMeta.getSelectedSteps(); // Adjust location of selected steps... if (selected_steps != null) for (int i = 0; i < selected_steps.length; i++) { StepMeta stepMeta = selected_steps[i]; stepMeta.setLocation(stepMeta.getLocation().x + dx, stepMeta.getLocation().y + dy); } // Adjust location of selected hops... if (selected_notes != null) for (int i = 0; i < selected_notes.length; i++) { NotePadMeta ni = selected_notes[i]; ni.setLocation(ni.getLocation().x + dx, ni.getLocation().y + dy); } redraw(); } // The middle button perhaps? else if (last_button == 2 || (last_button == 1 && shift)) { StepMeta stepMeta = transMeta.getStep(real.x, real.y, iconsize); if (stepMeta != null && !selected_step.equals(stepMeta)) { if (candidate == null) { candidate = new TransHopMeta(selected_step, stepMeta); redraw(); } } else { if (candidate != null) { candidate = null; redraw(); } } } } // Move around notes & steps else if (selected_note != null) { if (last_button == 1 && !shift) { /* * One or more notes are selected and moved around... * * new : new position of the note (not the mouse pointer) dx : difference with previous * position */ int dx = note.x - selected_note.getLocation().x; int dy = note.y - selected_note.getLocation().y; selected_notes = transMeta.getSelectedNotes(); selected_steps = transMeta.getSelectedSteps(); // Adjust location of selected steps... if (selected_steps != null) for (int i = 0; i < selected_steps.length; i++) { StepMeta stepMeta = selected_steps[i]; stepMeta.setLocation(stepMeta.getLocation().x + dx, stepMeta.getLocation().y + dy); } // Adjust location of selected hops... if (selected_notes != null) for (int i = 0; i < selected_notes.length; i++) { NotePadMeta ni = selected_notes[i]; ni.setLocation(ni.getLocation().x + dx, ni.getLocation().y + dy); } redraw(); } } } }); // 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) { clearSettings(); 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; } // System.out.println("Dropping a step!!"); // What's the real drop position? Point p = getRealPosition(canvas, event.x, event.y); // // We expect a Drag and Drop container... (encased in XML) try { DragAndDropContainer container = (DragAndDropContainer) event.data; StepMeta stepMeta = null; boolean newstep = false; switch (container.getType()) { // Put an existing one on the canvas. case DragAndDropContainer.TYPE_STEP: { // Drop hidden step onto canvas.... stepMeta = transMeta.findStep(container.getData()); if (stepMeta != null) { if (stepMeta.isDrawn() || transMeta.isStepUsedInTransHops(stepMeta)) { MessageBox mb = new MessageBox(shell, SWT.OK); mb.setMessage( Messages.getString("SpoonGraph.Dialog.StepIsAlreadyOnCanvas.Message")); //$NON-NLS-1$ mb.setText(Messages.getString("SpoonGraph.Dialog.StepIsAlreadyOnCanvas.Title")); //$NON-NLS-1$ mb.open(); return; } // This step gets the drawn attribute and position set below. } else { // Unknown step dropped: ignore this to be safe! return; } } break; // Create a new step case DragAndDropContainer.TYPE_BASE_STEP_TYPE: { // Not an existing step: data refers to the type of step to create String steptype = container.getData(); stepMeta = spoon.newStep(transMeta, steptype, steptype, false, true); if (stepMeta != null) { newstep = true; } else { return; // Cancelled pressed in dialog or unable to create step. } } break; // Create a new TableInput step using the selected connection... case DragAndDropContainer.TYPE_DATABASE_CONNECTION: { newstep = true; String connectionName = container.getData(); TableInputMeta tii = new TableInputMeta(); tii.setDatabaseMeta(transMeta.findDatabase(connectionName)); StepLoader steploader = StepLoader.getInstance(); String stepID = steploader.getStepPluginID(tii); StepPlugin stepPlugin = steploader.findStepPluginWithID(stepID); String stepName = transMeta.getAlternativeStepname(stepPlugin.getDescription()); stepMeta = new StepMeta(stepID, stepName, tii); if (spoon.editStep(transMeta, stepMeta) != null) { transMeta.addStep(stepMeta); spoon.refreshTree(); spoon.refreshGraph(); } else { return; } } break; // Drag hop on the canvas: create a new Hop... case DragAndDropContainer.TYPE_TRANS_HOP: { newHop(); return; } default: { // Nothing we can use: give an error! MessageBox mb = new MessageBox(shell, SWT.OK); mb.setMessage(Messages.getString("SpoonGraph.Dialog.ItemCanNotBePlacedOnCanvas.Message")); //$NON-NLS-1$ mb.setText(Messages.getString("SpoonGraph.Dialog.ItemCanNotBePlacedOnCanvas.Title")); //$NON-NLS-1$ mb.open(); return; } } transMeta.unselectAll(); StepMeta before = (StepMeta) stepMeta.clone(); stepMeta.drawStep(); stepMeta.setSelected(true); stepMeta.setLocation(p.x, p.y); if (newstep) { spoon.addUndoNew(transMeta, new StepMeta[] { stepMeta }, new int[] { transMeta.indexOfStep(stepMeta) }); } else { spoon.addUndoChange(transMeta, new StepMeta[] { before }, new StepMeta[] { (StepMeta) stepMeta.clone() }, new int[] { transMeta.indexOfStep(stepMeta) }); } canvas.forceFocus(); redraw(); } catch (Exception e) { new ErrorDialog(shell, Messages.getString("SpoonGraph.Dialog.ErrorDroppingObject.Message"), Messages.getString("SpoonGraph.Dialog.ErrorDroppingObject.Title"), e); } } public void dropAccept(DropTargetEvent event) { } }); // Keyboard shortcuts... addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { // F2 --> rename step if (e.keyCode == SWT.F2) { renameStep(); } if (e.character == 1) // CTRL-A { transMeta.selectAll(); redraw(); } if (e.character == 3) // CTRL-C { spoon.copySelected(transMeta, transMeta.getSelectedSteps(), transMeta.getSelectedNotes()); } if (e.character == 22) // CTRL-V { spoon.pasteSteps(); } if (e.keyCode == SWT.ESC) { transMeta.unselectAll(); clearSettings(); redraw(); } if (e.keyCode == SWT.DEL) { StepMeta stepMeta[] = transMeta.getSelectedSteps(); if (stepMeta != null && stepMeta.length > 0) { delSelected(null); } } // 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); } // SPACE : over a step: show output fields... if (e.character == ' ' && lastMove != null) { Point real = screen2real(lastMove.x, lastMove.y); // Clear the tooltip! setToolTipText(null); // Set the pop-up menu StepMeta stepMeta = transMeta.getStep(real.x, real.y, iconsize); if (stepMeta != null) { // OK, we found a step, show the output fields... inputOutputFields(stepMeta, false); } } } }); addKeyListener(spoon.defKeys); setBackground(GUIResource.getInstance().getColorBackground()); setLayout(new FormLayout()); }
From source file:be.ibridge.kettle.spoon.SpoonLog.java
License:LGPL
public synchronized void start(TransExecutionConfiguration executionConfiguration) { if (!running) // Not running, start the transformation... {/*from w w w . j a v a 2s.co m*/ // Auto save feature... if (transMeta.hasChanged()) { if (spoon.props.getAutoSave()) { spoon.saveTransFile(transMeta); } else { MessageDialogWithToggle md = new MessageDialogWithToggle(shell, Messages.getString("SpoonLog.Dialog.FileHasChanged.Title"), //$NON-NLS-1$ null, Messages.getString("SpoonLog.Dialog.FileHasChanged1.Message") + Const.CR //$NON-NLS-1$ + Messages.getString("SpoonLog.Dialog.FileHasChanged2.Message") + 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("SpoonLog.Dialog.Option.AutoSaveTransformation"), //$NON-NLS-1$ spoon.props.getAutoSave()); int answer = md.open(); if ((answer & 0xFF) == 0) { spoon.saveTransFile(transMeta); } spoon.props.setAutoSave(md.getToggleState()); } } if (((transMeta.getName() != null && spoon.rep != null) || // Repository available & name set (transMeta.getFilename() != null && spoon.rep == null) // No repository & filename set ) && !transMeta.hasChanged() // Didn't change ) { if (trans == null || (trans != null && trans.isFinished())) { try { // Set the requested logging level. log.setLogLevel(executionConfiguration.getLogLevel()); trans = new Trans(log, transMeta.getFilename(), transMeta.getName(), new String[] { transMeta.getFilename() }); trans.setReplayDate(executionConfiguration.getReplayDate()); trans.open(spoon.rep, transMeta.getName(), transMeta.getDirectory().getPath(), transMeta.getFilename()); trans.setMonitored(true); log.logBasic(toString(), Messages.getString("SpoonLog.Log.TransformationOpened")); //$NON-NLS-1$ } catch (KettleException e) { trans = null; new ErrorDialog(shell, Messages.getString("SpoonLog.Dialog.ErrorOpeningTransformation.Title"), //$NON-NLS-1$ Messages.getString("SpoonLog.Dialog.ErrorOpeningTransformation.Message"), e); //$NON-NLS-1$ } readLog(); if (trans != null) { Row arguments = executionConfiguration.getArguments(); final String args[]; if (arguments != null) args = convertArguments(arguments); else args = null; setVariables(executionConfiguration); log.logMinimal(Spoon.APP_NAME, Messages.getString("SpoonLog.Log.LaunchingTransformation") //$NON-NLS-1$ + trans.getTransMeta().getName() + "]..."); //$NON-NLS-1$ trans.setSafeModeEnabled(executionConfiguration.isSafeModeEnabled()); // Launch the step preparation in a different thread. // That way Spoon doesn't block anymore and that way we can follow the progress of the initialisation // final Thread parentThread = Thread.currentThread(); display.asyncExec(new Runnable() { public void run() { prepareTrans(parentThread, args); } }); log.logMinimal(Spoon.APP_NAME, Messages.getString("SpoonLog.Log.StartedExecutionOfTransformation")); //$NON-NLS-1$ wStart.setEnabled(false); wStop.setEnabled(true); readLog(); } } else { MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING); m.setText(Messages.getString("SpoonLog.Dialog.DoNoStartTransformationTwice.Title")); //$NON-NLS-1$ m.setMessage(Messages.getString("SpoonLog.Dialog.DoNoStartTransformationTwice.Message")); //$NON-NLS-1$ m.open(); } } else { if (transMeta.hasChanged()) { MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING); m.setText(Messages.getString("SpoonLog.Dialog.SaveTransformationBeforeRunning.Title")); //$NON-NLS-1$ m.setMessage(Messages.getString("SpoonLog.Dialog.SaveTransformationBeforeRunning.Message")); //$NON-NLS-1$ m.open(); } else if (spoon.rep != null && transMeta.getName() == null) { MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING); m.setText(Messages.getString("SpoonLog.Dialog.GiveTransformationANameBeforeRunning.Title")); //$NON-NLS-1$ m.setMessage( Messages.getString("SpoonLog.Dialog.GiveTransformationANameBeforeRunning.Message")); //$NON-NLS-1$ m.open(); } else { MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING); m.setText(Messages.getString("SpoonLog.Dialog.SaveTransformationBeforeRunning2.Title")); //$NON-NLS-1$ m.setMessage(Messages.getString("SpoonLog.Dialog.SaveTransformationBeforeRunning2.Message")); //$NON-NLS-1$ m.open(); } } } }