Search in sources :

Example 36 with Wizard

use of org.eclipse.jface.wizard.Wizard in project pentaho-kettle by pentaho.

the class CreateDatabaseWizard method createAndRunDatabaseWizard.

/**
 * Shows a wizard that creates a new database connection...
 *
 * @param shell
 * @param props
 * @param databases
 * @return DatabaseMeta when finished or null when canceled
 */
public DatabaseMeta createAndRunDatabaseWizard(Shell shell, PropsUI props, List<DatabaseMeta> databases) {
    DatabaseMeta newDBInfo = new DatabaseMeta();
    final CreateDatabaseWizardPage1 page1 = new CreateDatabaseWizardPage1("1", props, newDBInfo, databases);
    final CreateDatabaseWizardPageInformix pageifx = new CreateDatabaseWizardPageInformix("ifx", props, newDBInfo);
    final CreateDatabaseWizardPageJDBC pagejdbc = new CreateDatabaseWizardPageJDBC("jdbc", props, newDBInfo);
    final CreateDatabaseWizardPageOCI pageoci = new CreateDatabaseWizardPageOCI("oci", props, newDBInfo);
    final CreateDatabaseWizardPageODBC pageodbc = new CreateDatabaseWizardPageODBC("odbc", props, newDBInfo);
    final CreateDatabaseWizardPageOracle pageoracle = new CreateDatabaseWizardPageOracle("oracle", props, newDBInfo);
    final CreateDatabaseWizardPageGeneric pageGeneric = new CreateDatabaseWizardPageGeneric("generic", props, newDBInfo);
    final CreateDatabaseWizardPage2 page2 = new CreateDatabaseWizardPage2("2", props, newDBInfo);
    for (PluginInterface pluginInterface : PluginRegistry.getInstance().getPlugins(DatabasePluginType.class)) {
        try {
            Object plugin = PluginRegistry.getInstance().loadClass(pluginInterface);
            if (plugin instanceof WizardPageFactory) {
                WizardPageFactory factory = (WizardPageFactory) plugin;
                additionalPages.add(factory.createWizardPage(props, newDBInfo));
            }
        } catch (KettlePluginException kpe) {
        // Don't do anything
        }
    }
    // set to false for safety only
    wizardFinished = false;
    Wizard wizard = new Wizard() {

        /**
         * @see org.eclipse.jface.wizard.Wizard#performFinish()
         */
        public boolean performFinish() {
            wizardFinished = true;
            return true;
        }

        /**
         * @see org.eclipse.jface.wizard.Wizard#canFinish()
         */
        public boolean canFinish() {
            return page2.canFinish();
        }
    };
    wizard.addPage(page1);
    wizard.addPage(pageoci);
    wizard.addPage(pageodbc);
    wizard.addPage(pagejdbc);
    wizard.addPage(pageoracle);
    wizard.addPage(pageifx);
    wizard.addPage(pageGeneric);
    for (WizardPage page : additionalPages) {
        wizard.addPage(page);
    }
    wizard.addPage(page2);
    WizardDialog wd = new WizardDialog(shell, wizard);
    WizardDialog.setDefaultImage(GUIResource.getInstance().getImageWizard());
    wd.setMinimumPageSize(700, 400);
    wd.updateSize();
    wd.open();
    if (!wizardFinished) {
        newDBInfo = null;
    }
    return newDBInfo;
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) WizardPage(org.eclipse.jface.wizard.WizardPage) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 37 with Wizard

use of org.eclipse.jface.wizard.Wizard in project pentaho-kettle by pentaho.

the class TextFileInputDialog method getFixed.

private void getFixed() {
    TextFileInputMeta info = new TextFileInputMeta();
    getInfo(info, true);
    Shell sh = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    try {
        List<String> rows = getFirst(50, false);
        fields = getFields(info, rows);
        final TextFileImportWizardPage1 page1 = new TextFileImportWizardPage1("1", props, rows, fields);
        page1.createControl(sh);
        final TextFileImportWizardPage2 page2 = new TextFileImportWizardPage2("2", props, rows, fields);
        page2.createControl(sh);
        Wizard wizard = new Wizard() {

            public boolean performFinish() {
                wFields.clearAll(false);
                for (TextFileInputFieldInterface field1 : fields) {
                    BaseFileField field = (BaseFileField) field1;
                    if (!field.isIgnored() && field.getLength() > 0) {
                        TableItem item = new TableItem(wFields.table, SWT.NONE);
                        item.setText(1, field.getName());
                        item.setText(2, "" + field.getTypeDesc());
                        item.setText(3, "" + field.getFormat());
                        item.setText(4, "" + field.getPosition());
                        item.setText(5, field.getLength() < 0 ? "" : "" + field.getLength());
                        item.setText(6, field.getPrecision() < 0 ? "" : "" + field.getPrecision());
                        item.setText(7, "" + field.getCurrencySymbol());
                        item.setText(8, "" + field.getDecimalSymbol());
                        item.setText(9, "" + field.getGroupSymbol());
                        item.setText(10, "" + field.getNullString());
                        item.setText(11, "" + field.getIfNullValue());
                        item.setText(12, "" + field.getTrimTypeDesc());
                        item.setText(13, field.isRepeated() ? BaseMessages.getString(PKG, "System.Combo.Yes") : BaseMessages.getString(PKG, "System.Combo.No"));
                    }
                }
                int size = wFields.table.getItemCount();
                if (size == 0) {
                    new TableItem(wFields.table, SWT.NONE);
                }
                wFields.removeEmptyRows();
                wFields.setRowNums();
                wFields.optWidth(true);
                input.setChanged();
                return true;
            }
        };
        wizard.addPage(page1);
        wizard.addPage(page2);
        WizardDialog wd = new WizardDialog(shell, wizard);
        WizardDialog.setDefaultImage(GUIResource.getInstance().getImageWizard());
        wd.setMinimumPageSize(700, 375);
        wd.updateSize();
        wd.open();
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogMessage"), e);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) BaseFileField(org.pentaho.di.trans.steps.file.BaseFileField) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) Shell(org.eclipse.swt.widgets.Shell) TextFileInputMeta(org.pentaho.di.trans.steps.fileinput.text.TextFileInputMeta) TextFileInputFieldInterface(org.pentaho.di.core.gui.TextFileInputFieldInterface) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 38 with Wizard

use of org.eclipse.jface.wizard.Wizard in project pentaho-kettle by pentaho.

the class FixedInputDialog method getFixed.

private void getFixed() {
    final FixedInputMeta info = new FixedInputMeta();
    getInfo(info);
    Shell sh = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    try {
        List<String> rows = getFirst(info, 50);
        fields = new ArrayList<FixedFileInputField>();
        fields.addAll(Arrays.asList(info.getFieldDefinition()));
        if (fields.isEmpty()) {
            FixedFileInputField field = new FixedFileInputField();
            // TODO: i18n, see also FixedTableDraw class for other references of this String
            field.setName("Field" + 1);
            // --> getNewFieldname() method
            field.setType(ValueMetaInterface.TYPE_STRING);
            field.setTrimType(ValueMetaInterface.TRIM_TYPE_NONE);
            field.setWidth(Const.toInt(info.getLineWidth(), 80));
            field.setLength(-1);
            field.setPrecision(-1);
            fields.add(field);
        } else if (info.hasChanged()) {
            // try to reuse the field mappings already set up.
            int width = 0;
            List<FixedFileInputField> reuse = new ArrayList<FixedFileInputField>();
            for (FixedFileInputField field : fields) {
                width += field.getWidth();
                // does this field fit on the line given the line width?
                if (width <= Const.toInt(info.getLineWidth(), width)) {
                    // yes, reuse it
                    reuse.add(field);
                } else {
                    // no, remove its width from the total reused width then quit looking for more
                    width -= field.getWidth();
                    continue;
                }
            }
            int lineWidth = Const.toInt(info.getLineWidth(), width);
            // set the last reused field to take up the rest of the line.
            FixedFileInputField lastField = reuse.get(reuse.size() - 1);
            // don't let the width be grater than the line width
            if (width > lineWidth) {
                width = lineWidth;
            }
            // determine width of last field : lineWidth - (totalWidthOfFieldsReused - lastFieldWidth)
            int lastWidth = Const.toInt(info.getLineWidth(), width) - (width - lastField.getWidth());
            // make the last field occupy the remaining space
            lastField.setWidth(lastWidth);
            // reuse the fields...
            fields = reuse;
        }
        final FixedFileImportWizardPage1 page1 = new FixedFileImportWizardPage1("1", props, rows, fields);
        page1.createControl(sh);
        final FixedFileImportWizardPage2 page2 = new FixedFileImportWizardPage2("2", props, rows, fields);
        page2.createControl(sh);
        Wizard wizard = new Wizard() {

            public boolean performFinish() {
                wFields.clearAll(false);
                for (int i = 0; i < fields.size(); i++) {
                    FixedFileInputField field = fields.get(i);
                    if (field.getWidth() > 0) {
                        TableItem item = new TableItem(wFields.table, SWT.NONE);
                        item.setText(1, field.getName());
                        item.setText(2, "" + ValueMetaFactory.getValueMetaName(field.getType()));
                        item.setText(3, "" + field.getFormat());
                        item.setText(4, "" + field.getWidth());
                        item.setText(5, field.getLength() < 0 ? "" : "" + field.getLength());
                        item.setText(6, field.getPrecision() < 0 ? "" : "" + field.getPrecision());
                        item.setText(7, "" + field.getCurrency());
                        item.setText(8, "" + field.getDecimal());
                        item.setText(9, "" + field.getGrouping());
                    }
                }
                int size = wFields.table.getItemCount();
                if (size == 0) {
                    new TableItem(wFields.table, SWT.NONE);
                }
                wFields.removeEmptyRows();
                wFields.setRowNums();
                wFields.optWidth(true);
                inputMeta.setChanged();
                return true;
            }
        };
        wizard.addPage(page1);
        wizard.addPage(page2);
        WizardDialog wd = new WizardDialog(shell, wizard);
        WizardDialog.setDefaultImage(GUIResource.getInstance().getImageWizard());
        wd.setMinimumPageSize(700, 375);
        wd.updateSize();
        wd.open();
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "FixedInputDialog.ErrorShowingFixedWizard.DialogTitle"), BaseMessages.getString(PKG, "FixedInputDialog.ErrorShowingFixedWizard.DialogMessage"), e);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleValueException(org.pentaho.di.core.exception.KettleValueException) IOException(java.io.IOException) FixedFileInputField(org.pentaho.di.trans.steps.fixedinput.FixedFileInputField) Shell(org.eclipse.swt.widgets.Shell) List(java.util.List) ArrayList(java.util.ArrayList) FixedInputMeta(org.pentaho.di.trans.steps.fixedinput.FixedInputMeta) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 39 with Wizard

use of org.eclipse.jface.wizard.Wizard in project pentaho-kettle by pentaho.

the class TextFileInputDialog method getFixed.

private void getFixed() {
    TextFileInputMeta info = new TextFileInputMeta();
    getInfo(info);
    Shell sh = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
    try {
        List<String> rows = getFirst(50, false);
        fields = getFields(info, rows);
        final TextFileImportWizardPage1 page1 = new TextFileImportWizardPage1("1", props, rows, fields);
        page1.createControl(sh);
        final TextFileImportWizardPage2 page2 = new TextFileImportWizardPage2("2", props, rows, fields);
        page2.createControl(sh);
        Wizard wizard = new Wizard() {

            public boolean performFinish() {
                wFields.clearAll(false);
                for (TextFileInputFieldInterface field1 : fields) {
                    TextFileInputField field = (TextFileInputField) field1;
                    if (!field.isIgnored() && field.getLength() > 0) {
                        TableItem item = new TableItem(wFields.table, SWT.NONE);
                        item.setText(1, field.getName());
                        item.setText(2, "" + field.getTypeDesc());
                        item.setText(3, "" + field.getFormat());
                        item.setText(4, "" + field.getPosition());
                        item.setText(5, field.getLength() < 0 ? "" : "" + field.getLength());
                        item.setText(6, field.getPrecision() < 0 ? "" : "" + field.getPrecision());
                        item.setText(7, "" + field.getCurrencySymbol());
                        item.setText(8, "" + field.getDecimalSymbol());
                        item.setText(9, "" + field.getGroupSymbol());
                        item.setText(10, "" + field.getNullString());
                        item.setText(11, "" + field.getIfNullValue());
                        item.setText(12, "" + field.getTrimTypeDesc());
                        item.setText(13, field.isRepeated() ? BaseMessages.getString(PKG, "System.Combo.Yes") : BaseMessages.getString(PKG, "System.Combo.No"));
                    }
                }
                int size = wFields.table.getItemCount();
                if (size == 0) {
                    new TableItem(wFields.table, SWT.NONE);
                }
                wFields.removeEmptyRows();
                wFields.setRowNums();
                wFields.optWidth(true);
                input.setChanged();
                return true;
            }
        };
        wizard.addPage(page1);
        wizard.addPage(page2);
        WizardDialog wd = new WizardDialog(shell, wizard);
        WizardDialog.setDefaultImage(GUIResource.getInstance().getImageWizard());
        wd.setMinimumPageSize(700, 375);
        wd.updateSize();
        wd.open();
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogTitle"), BaseMessages.getString(PKG, "TextFileInputDialog.ErrorShowingFixedWizard.DialogMessage"), e);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) Shell(org.eclipse.swt.widgets.Shell) TextFileInputMeta(org.pentaho.di.trans.steps.textfileinput.TextFileInputMeta) TextFileInputFieldInterface(org.pentaho.di.core.gui.TextFileInputFieldInterface) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 40 with Wizard

use of org.eclipse.jface.wizard.Wizard in project erlide_eclipse by erlang.

the class ErlangFileWizard method performFinish.

/**
 * This method is called when 'Finish' button is pressed in the wizard. We will create
 * an operation and run it using wizard as execution context.
 */
@Override
public boolean performFinish() {
    final String containerName = fPage.getContainerName();
    final String fileName = fPage.getFileName();
    final String skeleton = fPage.getSkeleton();
    final IRunnableWithProgress op = monitor -> {
        try {
            doFinish(containerName, fileName, skeleton, monitor);
        } catch (final CoreException e) {
            throw new InvocationTargetException(e);
        } finally {
            monitor.done();
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (final InterruptedException e) {
        return false;
    } catch (final InvocationTargetException e) {
        final Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}
Also used : ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) IDE(org.eclipse.ui.ide.IDE) IWorkbenchWizard(org.eclipse.ui.IWorkbenchWizard) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer) IStatus(org.eclipse.core.runtime.IStatus) ByteArrayInputStream(java.io.ByteArrayInputStream) IPath(org.eclipse.core.runtime.IPath) PartInitException(org.eclipse.ui.PartInitException) IFile(org.eclipse.core.resources.IFile) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) PlatformUI(org.eclipse.ui.PlatformUI) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) Wizard(org.eclipse.jface.wizard.Wizard) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResource(org.eclipse.core.resources.IResource) Path(org.eclipse.core.runtime.Path) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) INewWizard(org.eclipse.ui.INewWizard) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbench(org.eclipse.ui.IWorkbench) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CommonUtils(org.erlide.engine.util.CommonUtils) InputStream(java.io.InputStream) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

Wizard (org.eclipse.jface.wizard.Wizard)40 WizardDialog (org.eclipse.jface.wizard.WizardDialog)34 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CoreException (org.eclipse.core.runtime.CoreException)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 IOException (java.io.IOException)6 IFile (org.eclipse.core.resources.IFile)6 Path (org.eclipse.core.runtime.Path)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 Shell (org.eclipse.swt.widgets.Shell)5 InvalidAlgorithmParameterException (de.flexiprovider.api.exceptions.InvalidAlgorithmParameterException)4 NoSuchAlgorithmException (de.flexiprovider.api.exceptions.NoSuchAlgorithmException)4 AlgorithmParameterSpec (de.flexiprovider.api.parameters.AlgorithmParameterSpec)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IContainer (org.eclipse.core.resources.IContainer)4 IResource (org.eclipse.core.resources.IResource)4 ResourcesPlugin (org.eclipse.core.resources.ResourcesPlugin)4 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 INewWizard (org.eclipse.ui.INewWizard)4