Search in sources :

Example 21 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class SpoonLockController method viewLockNote.

public void viewLockNote() throws Exception {
    if (workingMeta != null && supportsLocking(Spoon.getInstance().getRepository())) {
        try {
            RepositoryLock repoLock = fetchRepositoryLock(workingMeta);
            if (repoLock != null) {
                // $NON-NLS-1$
                XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
                // $NON-NLS-1$
                msgBox.setTitle(BaseMessages.getString(PKG, "PurRepository.LockNote.Title"));
                msgBox.setMessage(repoLock.getMessage());
                msgBox.setModalParent(shell);
                msgBox.open();
            }
        } catch (Throwable th) {
            // $NON-NLS-1$
            log.error(BaseMessages.getString(PKG, "LockController.NoLockingSupport"), th);
            new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), BaseMessages.getString(PKG, "Dialog.Error"), BaseMessages.getString(PKG, "LockController.NoLockingSupport"), // $NON-NLS-1$ //$NON-NLS-2$
            th);
        }
    } else {
        // $NON-NLS-1$
        XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
        // $NON-NLS-1$
        msgBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
        // $NON-NLS-1$
        msgBox.setMessage(BaseMessages.getString(PKG, "LockController.NoLockingSupport"));
        msgBox.setModalParent(shell);
        msgBox.open();
    }
}
Also used : XulMessageBox(org.pentaho.ui.xul.components.XulMessageBox) Spoon(org.pentaho.di.ui.spoon.Spoon) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock)

Example 22 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class SpoonLockController method lockContent.

public void lockContent() throws Exception {
    try {
        if (workingMeta != null && workingMeta.getObjectId() != null && supportsLocking(Spoon.getInstance().getRepository())) {
            // Look in the SpoonTransformationDelegate for details on the TabItem creation
            if (!tabBound) {
                bindingFactory.createBinding(this, "activeMetaUnlocked", Spoon.getInstance().delegates.tabs.findTabMapEntry(workingMeta).getTabItem(), "image", new // $NON-NLS-1$ //$NON-NLS-2$
                BindingConvertor<Boolean, Image>() {

                    @Override
                    public Image sourceToTarget(Boolean activeMetaUnlocked) {
                        if (activeMetaUnlocked) {
                            if (workingMeta instanceof TransMeta) {
                                return GUIResource.getInstance().getImageTransGraph();
                            } else if (workingMeta instanceof JobMeta) {
                                return GUIResource.getInstance().getImageJobGraph();
                            }
                        } else {
                            return GUIResource.getInstance().getImageLocked();
                        }
                        return null;
                    }

                    @Override
                    public Boolean targetToSource(Image arg0) {
                        return false;
                    }
                });
                tabBound = true;
            }
            // Decide whether to lock or unlock the object
            if (fetchRepositoryLock(workingMeta) == null) {
                // Lock the object (it currently is NOT locked)
                XulPromptBox lockNotePrompt = promptLockMessage(document, messages, null);
                lockNotePrompt.addDialogCallback(new XulDialogCallback<String>() {

                    public void onClose(XulComponent component, Status status, String value) {
                        if (!status.equals(Status.CANCEL)) {
                            try {
                                if (workingMeta instanceof TransMeta) {
                                    getService(Spoon.getInstance().getRepository()).lockTransformation(workingMeta.getObjectId(), value);
                                } else if (workingMeta instanceof JobMeta) {
                                    getService(Spoon.getInstance().getRepository()).lockJob(workingMeta.getObjectId(), value);
                                }
                                // Execute binding. Notify listeners that the object is now locked
                                // $NON-NLS-1$ //$NON-NLS-2$
                                firePropertyChange("activeMetaUnlocked", true, false);
                                // this keeps the menu item and the state in sync
                                // could a binding be used instead?
                                XulDomContainer container = getXulDomContainer();
                                XulMenuitem lockMenuItem = // $NON-NLS-1$
                                (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
                                lockMenuItem.setSelected(true);
                            } catch (Exception e) {
                                // convert to runtime exception so it bubbles up through the UI
                                throw new RuntimeException(e);
                            }
                        } else {
                            // this keeps the menu item and the state in sync
                            // could a binding be used instead?
                            XulDomContainer container = getXulDomContainer();
                            XulMenuitem lockMenuItem = // $NON-NLS-1$
                            (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
                            lockMenuItem.setSelected(false);
                        }
                    }

                    public void onError(XulComponent component, Throwable err) {
                        throw new RuntimeException(err);
                    }
                });
                lockNotePrompt.open();
            } else {
                // Unlock the object (it currently IS locked)
                if (workingMeta instanceof TransMeta) {
                    getService(Spoon.getInstance().getRepository()).unlockTransformation(workingMeta.getObjectId());
                } else if (workingMeta instanceof JobMeta) {
                    getService(Spoon.getInstance().getRepository()).unlockJob(workingMeta.getObjectId());
                }
                // Execute binding. Notify listeners that the object is now unlocked
                // $NON-NLS-1$ //$NON-NLS-2$
                firePropertyChange("activeMetaUnlocked", false, true);
            }
        } else if (workingMeta != null && workingMeta.getObjectId() == null && supportsLocking(Spoon.getInstance().getRepository())) {
            XulDomContainer container = getXulDomContainer();
            // $NON-NLS-1$
            XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
            lockMenuItem.setSelected(false);
            // $NON-NLS-1$
            XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
            // $NON-NLS-1$
            msgBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            // $NON-NLS-1$
            msgBox.setMessage(BaseMessages.getString(PKG, "LockController.SaveBeforeLock"));
            msgBox.setModalParent(shell);
            msgBox.open();
        } else {
            XulDomContainer container = getXulDomContainer();
            // $NON-NLS-1$
            XulMenuitem lockMenuItem = (XulMenuitem) container.getDocumentRoot().getElementById("lock-context-lock");
            lockMenuItem.setSelected(false);
            // $NON-NLS-1$
            XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
            // $NON-NLS-1$
            msgBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            // $NON-NLS-1$
            msgBox.setMessage(BaseMessages.getString(PKG, "LockController.NoLockingSupport"));
            msgBox.setModalParent(shell);
            msgBox.open();
        }
    } catch (Throwable th) {
        // $NON-NLS-1$
        log.error(BaseMessages.getString(PKG, "LockController.NoLockingSupport"), th);
        new ErrorDialog(((Spoon) SpoonFactory.getInstance()).getShell(), BaseMessages.getString(PKG, "Dialog.Error"), BaseMessages.getString(PKG, "LockController.NoLockingSupport"), // $NON-NLS-1$ //$NON-NLS-2$
        th);
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) Image(org.eclipse.swt.graphics.Image) XulDomContainer(org.pentaho.ui.xul.XulDomContainer) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) XulMessageBox(org.pentaho.ui.xul.components.XulMessageBox) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) XulPromptBox(org.pentaho.ui.xul.components.XulPromptBox) Spoon(org.pentaho.di.ui.spoon.Spoon) XulComponent(org.pentaho.ui.xul.XulComponent)

Example 23 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class CustomAuthorizationCodeInstalledApp method onAuthorization.

protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException {
    String url = authorizationUrl.build();
    Spoon spoon = Spoon.getInstance();
    if (spoon != null) {
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                Shell shell = spoon.getShell();
                GoogleAuthorizationDialog authorizationDialog = new GoogleAuthorizationDialog(shell, getReceiver());
                authorizationDialog.open(url);
            }
        });
    } else {
        browse(url);
    }
}
Also used : GoogleAuthorizationDialog(org.pentaho.googledrive.vfs.ui.GoogleAuthorizationDialog) Shell(org.eclipse.swt.widgets.Shell) Spoon(org.pentaho.di.ui.spoon.Spoon)

Example 24 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class RepositoryVfsProvider method registerRepoVFS.

private void registerRepoVFS() {
    FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager();
    if (fsm instanceof DefaultFileSystemManager) {
        try {
            ((DefaultFileSystemManager) fsm).addProvider(SCHEME, this);
            final Spoon spoon = Spoon.getInstance();
            System.out.println();
        } catch (Exception ex) {
            throw new RuntimeException("Error initialize repo:// VFS", ex);
        }
    }
}
Also used : Spoon(org.pentaho.di.ui.spoon.Spoon) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) NotImplementedException(org.apache.commons.lang.NotImplementedException)

Example 25 with Spoon

use of org.pentaho.di.ui.spoon.Spoon in project pentaho-kettle by pentaho.

the class JobEntryTransDialog method pickFileVFS.

protected void pickFileVFS() {
    FileDialog dialog = new FileDialog(shell, SWT.OPEN);
    dialog.setFilterExtensions(Const.STRING_TRANS_FILTER_EXT);
    dialog.setFilterNames(Const.getTransformationFilterNames());
    String prevName = jobMeta.environmentSubstitute(wPath.getText());
    String parentFolder = null;
    try {
        parentFolder = KettleVFS.getFilename(KettleVFS.getFileObject(jobMeta.environmentSubstitute(jobMeta.getFilename())).getParent());
    } catch (Exception e) {
    // not that important
    }
    if (!Utils.isEmpty(prevName)) {
        try {
            if (KettleVFS.fileExists(prevName)) {
                dialog.setFilterPath(KettleVFS.getFilename(KettleVFS.getFileObject(prevName).getParent()));
            } else {
                if (!prevName.endsWith(".ktr")) {
                    prevName = getEntryName(Const.trim(wPath.getText()) + ".ktr");
                }
                if (KettleVFS.fileExists(prevName)) {
                    specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
                    wPath.setText(prevName);
                    return;
                } else {
                    // File specified doesn't exist. Ask if we should create the file...
                    // 
                    MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                    mb.setMessage(BaseMessages.getString(PKG, "JobTrans.Dialog.CreateTransformationQuestion.Message"));
                    // Sorry!
                    mb.setText(BaseMessages.getString(PKG, "JobTrans.Dialog.CreateTransformationQuestion.Title"));
                    int answer = mb.open();
                    if (answer == SWT.YES) {
                        Spoon spoon = Spoon.getInstance();
                        spoon.newTransFile();
                        TransMeta transMeta = spoon.getActiveTransformation();
                        transMeta.initializeVariablesFrom(jobEntry);
                        transMeta.setFilename(jobMeta.environmentSubstitute(prevName));
                        wPath.setText(prevName);
                        specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
                        spoon.saveFile();
                        return;
                    }
                }
            }
        } catch (Exception e) {
            dialog.setFilterPath(parentFolder);
        }
    } else if (!Utils.isEmpty(parentFolder)) {
        dialog.setFilterPath(parentFolder);
    }
    String fname = dialog.open();
    if (fname != null) {
        File file = new File(fname);
        String name = file.getName();
        String parentFolderSelection = file.getParentFile().toString();
        if (!Utils.isEmpty(parentFolder) && parentFolder.equals(parentFolderSelection)) {
            wPath.setText(getEntryName(name));
        } else {
            wPath.setText(fname);
        }
    }
}
Also used : Spoon(org.pentaho.di.ui.spoon.Spoon) TransMeta(org.pentaho.di.trans.TransMeta) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) KettleException(org.pentaho.di.core.exception.KettleException) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

Spoon (org.pentaho.di.ui.spoon.Spoon)26 KettleException (org.pentaho.di.core.exception.KettleException)11 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)8 TransMeta (org.pentaho.di.trans.TransMeta)6 JobMeta (org.pentaho.di.job.JobMeta)5 XulException (org.pentaho.ui.xul.XulException)5 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)5 File (java.io.File)3 Shell (org.eclipse.swt.widgets.Shell)3 Test (org.junit.Test)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 PurRepository (org.pentaho.di.repository.pur.PurRepository)3 RepositoryLock (org.pentaho.di.repository.pur.model.RepositoryLock)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 EngineMetaInterface (org.pentaho.di.core.EngineMetaInterface)2