Example usage for org.eclipse.jface.dialogs MessageDialog WARNING

List of usage examples for org.eclipse.jface.dialogs MessageDialog WARNING

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog WARNING.

Prototype

int WARNING

To view the source code for org.eclipse.jface.dialogs MessageDialog WARNING.

Click Source Link

Document

Constant for the warning image, or a simple dialog with the warning image and a single OK button (value 4).

Usage

From source file:org.mwc.debrief.core.editors.PlotEditor.java

License:Open Source License

/**
 * @see org.eclipse.ui.IEditorPart#doSave(IProgressMonitor)
 *//*www .  j a  v a 2s. co  m*/
public void doSave(final IProgressMonitor monitor) {
    final IEditorInput input = getEditorInput();
    String ext = null;

    // do we have an input
    if (input.exists()) {
        // get the file suffix
        if (input instanceof IFileEditorInput) {
            IFile file = null;
            file = ((IFileEditorInput) getEditorInput()).getFile();
            final IPath path = file.getFullPath();
            ext = path.getFileExtension();
        } else if (input instanceof FileStoreEditorInput) {
            final FileStoreEditorInput fi = (FileStoreEditorInput) input;
            final URI uri = fi.getURI();
            final Path path = new Path(uri.getPath());
            ext = path.getFileExtension();
        }

        // right, have a look at it.
        if ((ext == null) || (!ext.equalsIgnoreCase("xml") && !ext.equalsIgnoreCase("dpf"))) {
            String msg = "Debrief stores data in a structured (xml) text format,";
            msg += "\nwhich is different to the format you've used to load the data.";
            msg += "\nThus you must specify an existing (or new) folder to "
                    + "store the plot,\nand provide new filename.";
            msg += "\nNote: it's important that you give the file a .dpf file suffix";
            final MessageDialog md = new MessageDialog(getEditorSite().getShell(), "Save as", null, msg,
                    MessageDialog.WARNING, new String[] { "Ok" }, 0);
            md.open();

            // not, we have to do a save-as
            doSaveAs(
                    "Can't store this file-type, select a target folder, and remember to save as Debrief plot-file (*.dpf)");
        } else {

            OutputStream tmpOS = null;
            // the workspace has a listenser that will close/rename the current plot
            // editor if it's parent file
            // has been deleted/renamed. We need to cancel that processing whilst we
            // do a file-save,
            // since the file-save includes a name-change.
            ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
            try {
                // NEW STRATEGY. Save to tmp first, then overwrite existing on
                // success.

                // 1. create the temp file
                final File tmpFile = File.createTempFile("DebNG_tmp", ".dpf");
                tmpFile.createNewFile();
                tmpFile.deleteOnExit();

                // 1a. record the name of the tmp file in the log
                final String filePath = tmpFile.getAbsolutePath();
                CorePlugin.logError(Status.INFO, "Created temp save file at:" + filePath, null);

                // 2. open the file as a stream
                tmpOS = new FileOutputStream(tmpFile);

                // 3. save to this stream
                doSaveTo(tmpOS, monitor);

                tmpOS.close();
                tmpOS = null;

                // sort out the file size
                CorePlugin.logError(Status.INFO, "Saved file size is:" + tmpFile.length() / 1024 + " Kb", null);

                // 4. Check there's something in the temp file
                if (tmpFile.exists())
                    if (tmpFile.length() == 0) {
                        // save failed throw exception (to be collected shortly
                        // afterwards)
                        throw new RuntimeException("Stored file is of zero size");
                    } else {

                        // save worked. cool.

                        // 5. overwrite the existing file with the saved file
                        // - note we will only reach this point if the save succeeded.
                        // sort out where we're saving to
                        if (input instanceof IFileEditorInput) {
                            CorePlugin.logError(Status.INFO, "Performing IFileEditorInput save", null);

                            final IFile file = ((IFileEditorInput) getEditorInput()).getFile();

                            // get the current path (since we're going to be moving the temp
                            // one to it
                            final IPath thePath = file.getLocation();

                            // create a backup path
                            final IPath bakPath = file.getFullPath().addFileExtension("bak");

                            // delete any existing backup file
                            final File existingBackupFile = new File(
                                    file.getLocation().addFileExtension("bak").toOSString());
                            if (existingBackupFile.exists()) {
                                CorePlugin.logError(Status.INFO,
                                        "Existing back file still there, having to delete"
                                                + existingBackupFile.getAbsolutePath(),
                                        null);
                                existingBackupFile.delete();
                            }

                            // now rename the existing file as the backup
                            file.move(bakPath, true, monitor);

                            // move the temp file to be our real working file
                            final File destFile = thePath.toFile().getAbsoluteFile();
                            if (!tmpFile.renameTo(destFile)) {
                                FileUtils.moveFile(tmpFile, destFile);
                            }

                            // finally, delete the backup file
                            if (existingBackupFile.exists()) {
                                CorePlugin.logError(Status.INFO,
                                        "Save operation completed successfully, deleting backup file"
                                                + existingBackupFile.getAbsolutePath(),
                                        null);
                                existingBackupFile.delete();
                            }

                            // throw in a refresh - since we've done the save outside
                            // Eclipse
                            file.getParent().refreshLocal(IResource.DEPTH_INFINITE, monitor);

                        } else if (input instanceof FileStoreEditorInput) {

                            CorePlugin.logError(Status.INFO, "Performing FileStoreEditorInput save", null);

                            // get the data-file
                            final FileStoreEditorInput fi = (FileStoreEditorInput) input;
                            final URI _uri = fi.getURI();
                            final Path _p = new Path(_uri.getPath());

                            // create pointers to the existing file, and the backup file
                            final IFileStore existingFile = EFS.getLocalFileSystem().getStore(_p);
                            final IFileStore backupFile = EFS.getLocalFileSystem()
                                    .getStore(_p.addFileExtension("bak"));

                            // delete any existing backup file
                            final IFileInfo backupStatus = backupFile.fetchInfo();
                            if (backupStatus.exists()) {
                                CorePlugin.logError(Status.INFO,
                                        "Existing back file still there, having to delete"
                                                + backupFile.toURI().getRawPath(),
                                        null);
                                backupFile.delete(EFS.NONE, monitor);
                            }

                            // now rename the existing file as the backup
                            existingFile.move(backupFile, EFS.OVERWRITE, monitor);

                            // and rename the temp file as the working file
                            tmpFile.renameTo(existingFile.toLocalFile(EFS.NONE, monitor));

                            if (backupStatus.exists()) {
                                CorePlugin.logError(Status.INFO,
                                        "Save operation successful, deleting backup file"
                                                + backupFile.toURI().getRawPath(),
                                        null);
                                backupFile.delete(EFS.NONE, monitor);
                            }

                        }
                    }
            } catch (final CoreException e) {
                CorePlugin.logError(Status.ERROR, "Failed whilst saving external file", e);
            } catch (final FileNotFoundException e) {
                CorePlugin.logError(Status.ERROR, "Failed to find local file to save to", e);
            } catch (final Exception e) {
                CorePlugin.logError(Status.ERROR, "Unknown file-save error occurred", e);
            } finally {
                try {
                    if (tmpOS != null)
                        tmpOS.close();
                } catch (final IOException e) {
                    CorePlugin.logError(Status.ERROR, "Whilst performing save", e);
                }
                ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener,
                        IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE
                                | IResourceChangeEvent.POST_CHANGE);
            }
        }
    }
}

From source file:org.mwc.debrief.core.editors.PlotEditor.java

License:Open Source License

public void doSaveAs(final String message) {
    // do we have a project?
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject[] projects = workspace.getRoot().getProjects();
    if ((projects == null) || (projects.length == 0)) {
        String msg = "Debrief plots are stored in 'Projects'";
        msg += "\nBut you do not yet have one defined.";
        msg += "\nPlease follow the 'Generating a project for your data' cheat";
        msg += "\nsheet, accessed from Help/Cheat Sheets then Debrief/Getting started.";
        msg += "\nOnce you have created your project, please start the Save process again.";
        msg += "\nNote: the cheat sheet will open automatically when you close this dialog.";
        final MessageDialog md = new MessageDialog(getEditorSite().getShell(), "Save as", null, msg,
                MessageDialog.WARNING, new String[] { "Ok" }, 0);
        md.open();/*from  w  ww  . j  a  va2s .  co  m*/

        // try to open the cheat sheet
        final String CHEAT_ID = "org.mwc.debrief.help.started.generate_project";

        Display.getCurrent().asyncExec(new Runnable() {
            public void run() {
                final OpenCheatSheetAction action = new OpenCheatSheetAction(CHEAT_ID);
                action.run();
            }
        });

        // ok, drop out - we can't do a save anyway
        return;
    }

    // get the workspace

    final SaveAsDialog dialog = new SaveAsDialog(getEditorSite().getShell());
    dialog.setTitle("Save Plot As");
    if (getEditorInput() instanceof FileEditorInput) {
        // this has been loaded from the navigator
        final IFile oldFile = ((FileEditorInput) getEditorInput()).getFile();
        // dialog.setOriginalFile(oldFile);

        final IPath oldPath = oldFile.getFullPath();
        final IPath newStart = oldPath.removeFileExtension();
        final IPath newPath = newStart.addFileExtension("dpf");
        final File asFile = newPath.toFile();
        final String newName = asFile.getName();
        dialog.setOriginalName(newName);
    } else if (getEditorInput() instanceof FileStoreEditorInput) {
        // this has been dragged from an explorer window
        final FileStoreEditorInput fi = (FileStoreEditorInput) getEditorInput();
        final URI uri = fi.getURI();
        final File thisFile = new File(uri.getPath());
        String newPath = fileNamePartOf(thisFile.getAbsolutePath());
        newPath += ".dpf";
        dialog.setOriginalName(newPath);
    }

    dialog.create();
    if (message != null)
        dialog.setMessage(message, IMessageProvider.WARNING);
    else
        dialog.setMessage("Save file to another location.");
    dialog.open();
    final IPath path = dialog.getResult();

    if (path == null) {
        return;
    } else {
        final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (!file.exists())
            try {
                System.out.println("creating:" + file.getName());
                file.create(new ByteArrayInputStream(new byte[] {}), false, null);
            } catch (final CoreException e) {
                DebriefPlugin.logError(IStatus.ERROR, "Failed trying to create new file for save-as", e);
                return;
            }

        OutputStream os = null;
        try {
            os = new FileOutputStream(file.getLocation().toFile(), false);
            // ok, write to the file
            doSaveTo(os, new NullProgressMonitor());

            // also make this new file our input
            final IFileEditorInput newInput = new FileEditorInput(file);
            setInputWithNotify(newInput);

            // lastly, trigger a navigator refresh
            final IFile iff = newInput.getFile();
            iff.refreshLocal(IResource.DEPTH_ONE, null);
            // refresh navigator
            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            IViewPart view = page.findView("org.eclipse.ui.views.ResourceNavigator");
            if (view instanceof ResourceNavigator) {
                ((ResourceNavigator) view).getViewer().refresh(iff);
            }
        } catch (final FileNotFoundException e) {
            CorePlugin.logError(Status.ERROR, "Failed whilst performing Save As", e);
        } catch (final CoreException e) {
            CorePlugin.logError(Status.ERROR, "Refresh failed after saving new file", e);
        } finally {
            // and close it
            try {
                if (os != null)
                    os.close();
            } catch (final IOException e) {
                CorePlugin.logError(Status.ERROR, "Whilst performaing save-as", e);
            }

        }

    }

    _plotIsDirty = false;
    firePropertyChange(PROP_DIRTY);
}

From source file:org.netxms.ui.eclipse.tools.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a standard warning dialog.
 * /*from w w w . ja va  2  s .  c om*/
 * @param parent the parent shell of the dialog, or <code>null</code> if none
 * @param title the dialog's title, or <code>null</code> if none
 * @param message the message
 */
public static void openWarning(Shell parent, String title, String message) {
    open(MessageDialog.WARNING, parent, title, message);
}

From source file:org.netxms.ui.eclipse.tools.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a standard warning dialog with a check box
 * to remember selection. /* w  w  w.java 2  s  . c o m*/
 * 
 * @param parent the parent shell of the dialog, or <code>null</code> if none
 * @param title the dialog's title, or <code>null</code> if none
 * @param label the label for the check box
 * @param message the message
 * @return 
 */
public static DialogData openWarningWithCheckbox(Shell parent, String title, String label, String message) {
    MessageDialogWithCheckbox msg = new MessageDialogWithCheckbox(MessageDialog.WARNING,
            new String[] { JFaceResources.getString(IDialogLabelKeys.OK_LABEL_KEY),
                    JFaceResources.getString(IDialogLabelKeys.CANCEL_LABEL_KEY) },
            parent, title, label, message);
    return msg.openMsg();
}

From source file:org.obeonetwork.dsl.uml2.design.api.services.ProfileDiagramServices.java

License:Open Source License

/**
 * Dialog message to undefine the profile.
 *
 * @param rootProfile/*from   w w  w .  j  a  v  a  2s.c o  m*/
 *            to undefine
 */
public void undefineProfileDialog(final Profile rootProfile) {
    final String[] buttonYesNo = { YES, NO };
    final String[] buttonYes = { OK };
    final Shell activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    MessageDialog msgDialogYesNo = null;
    MessageDialog msgDialogYes = null;
    if (rootProfile.getDefinition() != null) {
        msgDialogYesNo = new MessageDialog(activeShell, UNDEFINE_PROFILE, null,
                "Would you like to undefine this profile ?", MessageDialog.QUESTION, buttonYesNo, 1); //$NON-NLS-1$
        final int diagResult = msgDialogYesNo.open();
        if (diagResult == 0) {
            undefineProfile(rootProfile);
            msgDialogYes = new MessageDialog(activeShell, UNDEFINE_PROFILE, null, "The profile is undefined", //$NON-NLS-1$
                    MessageDialog.INFORMATION, buttonYes, 0);
            msgDialogYes.open();
        }
    } else {
        msgDialogYes = new MessageDialog(activeShell, UNDEFINE_PROFILE, null, "The profile is not defined !", //$NON-NLS-1$
                MessageDialog.WARNING, buttonYes, 0);
        msgDialogYes.open();
    }
}

From source file:org.obeonetwork.dsl.uml2.profile.design.services.UMLProfileServices.java

License:Open Source License

/**
 * Dialog message to undefine the profile.
 * /*from   w w w.j  av  a  2s  .  c  om*/
 * @param rootProfile
 *            to undefine
 */
public static void undefineProfileDialog(final Profile rootProfile) {
    final String[] buttonYesNo = { YES, NO };
    final String[] buttonYes = { OK };
    final Shell activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
    MessageDialog msgDialogYesNo = null;
    MessageDialog msgDialogYes = null;
    if (rootProfile.getDefinition() != null) {
        msgDialogYesNo = new MessageDialog(activeShell, undefineProfile, null,
                "Would you like to undefine this profile ?", MessageDialog.QUESTION, buttonYesNo, 1);
        final int diagResult = msgDialogYesNo.open();
        if (diagResult == 0) {
            undefineProfile(rootProfile);
            msgDialogYes = new MessageDialog(activeShell, undefineProfile, null, "The profile is undefined",
                    MessageDialog.INFORMATION, buttonYes, 0);
            msgDialogYes.open();
        }
    } else {
        msgDialogYes = new MessageDialog(activeShell, undefineProfile, null, "The profile is not defined !",
                MessageDialog.WARNING, buttonYes, 0);
        msgDialogYes.open();
    }
}

From source file:org.openbi.kettle.plugins.avrooutput.AvroOutputDialog.java

License:Apache License

public void updateTypes(RowMetaInterface row, TableView tableView, int nameColumn, int avroNameColumn,
        int[] typeColumn) {
    boolean createSchemaFile = wCreateSchemaFile.getSelection();
    if (validSchema || createSchemaFile) {
        Table table = tableView.table;/*from w w  w .j a v  a 2s. c  o m*/

        boolean typesPopulated = false;
        for (int i = 0; i < table.getItemCount(); i++) {
            TableItem tableItem = table.getItem(i);

            if (!typesPopulated) {
                for (int c = 0; c < typeColumn.length; c++) {
                    if (!Const.isEmpty(tableItem.getText(typeColumn[c]))) {
                        typesPopulated = true;
                        break;
                    }
                }
                if (typesPopulated) {
                    break;
                }
            }

        }

        int choice = 0;

        if (typesPopulated) {
            //Ask what we should sdo with the existing data
            MessageDialog md = new MessageDialog(tableView.getShell(),
                    BaseMessages.getString(PKG, "AvroOutputDialog.GetTypesChoice.Title"), null,
                    BaseMessages.getString(PKG, "AvroOutputDialog.GetTypesChoice.Message"),
                    MessageDialog.WARNING,
                    new String[] { BaseMessages.getString(PKG, "AvroOutputDialog.GetTypesChoice.AddNew"),
                            BaseMessages.getString(PKG, "AvroOutputDialog.GetTypesChoice.ReplaceAll"),
                            BaseMessages.getString(PKG, "AvroOutputDialog.GetTypesChoice.Cancel") },
                    0);
            MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
            int idx = md.open();
            choice = idx & 0xFF;
        }

        if (choice == 2 || choice == 255) {
            return; //nothing to do
        }

        for (int i = 0; i < table.getItemCount(); i++) {
            TableItem tableItem = table.getItem(i);
            String avroName = !(tableItem.getText(2).isEmpty()) ? tableItem.getText(2) : tableItem.getText(1);
            String streamName = tableItem.getText(1);
            logBasic("Stream name is " + streamName);
            if (!(avroName.isEmpty()) && !(createSchemaFile)) {
                Schema fieldSchema = getFieldSchema(avroName);
                if (fieldSchema != null) {
                    String[] types = AvroOutputField.mapAvroType(fieldSchema, fieldSchema.getType());
                    if (types.length > 0) {
                        for (int c = 0; c < typeColumn.length; c++) {
                            if (choice == 0 && !Const.isEmpty(tableItem.getText(typeColumn[c]))) {
                                //do nothing
                            } else {
                                tableItem.setText(typeColumn[c], types[0]);
                            }
                        }
                    } else if (choice == 1) {
                        for (int c = 0; c < typeColumn.length; c++) {
                            tableItem.setText(typeColumn[c], "");
                        }
                    }
                } else if (choice == 1) {
                    for (int c = 0; c < typeColumn.length; c++) {
                        tableItem.setText(typeColumn[c], "");
                    }
                }
            } else if (createSchemaFile && !(streamName.isEmpty())) { //create schema file
                logBasic("Create File");
                ValueMetaInterface v = row.searchValueMeta(streamName);
                logBasic(v != null ? v.getName() : "Value Meta is null");
                String avroType = "";
                if (v != null) {
                    avroType = AvroOutputField.getAvroTypeDesc(AvroOutputField.getDefaultAvroType(v.getType()));
                }
                for (int aTypeColumn : typeColumn) {
                    if (choice == 1 || (choice == 0 && (tableItem.getText(aTypeColumn).isEmpty()))) {
                        tableItem.setText(aTypeColumn, avroType);
                    }
                }
            }

        }
    } else {
        MessageDialog md = new MessageDialog(tableView.getShell(),
                BaseMessages.getString(PKG, "AvroOutputDialog.GetTypesChoice.BadSchema.Title"), null,
                BaseMessages.getString(PKG, "AvroOutputDialog.GetTypesChoice.BadSchema.Message"),
                MessageDialog.WARNING, new String[] { BaseMessages.getString(PKG, "System.Button.OK") }, 0);
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        int idx = md.open();
    }
}

From source file:org.openbi.kettle.plugins.avrooutput.AvroOutputDialog.java

License:Apache License

public void getFieldsFromPreviousAvro(RowMetaInterface row, TableView tableView, int keyColumn,
        int[] nameColumn, int[] avroNameColumn, int[] avroTypeColumn, TableItemInsertListener listener) {
    if (row == null || row.size() == 0) {
        return; // nothing to do
    }//from   ww  w  .j a v  a 2s .c  o m

    Table table = tableView.table;

    // get a list of all the non-empty keys (names)
    //
    List<String> keys = new ArrayList<String>();
    for (int i = 0; i < table.getItemCount(); i++) {
        TableItem tableItem = table.getItem(i);
        String key = tableItem.getText(keyColumn);
        if (!Const.isEmpty(key) && keys.indexOf(key) < 0) {
            keys.add(key);
        }
    }

    int choice = 0;

    if (keys.size() > 0) {
        // Ask what we should do with the existing data in the step.
        //
        MessageDialog md = new MessageDialog(tableView.getShell(),
                BaseMessages.getString(PKG, "BaseStepDialog.GetFieldsChoice.Title"), // "Warning!"
                null,
                BaseMessages.getString(
                        PKG, "BaseStepDialog.GetFieldsChoice.Message", "" + keys.size(), "" + row.size()),
                MessageDialog.WARNING,
                new String[] { BaseMessages.getString(PKG, "BaseStepDialog.AddNew"),
                        BaseMessages.getString(PKG, "BaseStepDialog.Add"),
                        BaseMessages.getString(PKG, "BaseStepDialog.ClearAndAdd"),
                        BaseMessages.getString(PKG, "BaseStepDialog.Cancel"), },
                0);
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        int idx = md.open();
        choice = idx & 0xFF;
    }

    if (choice == 3 || choice == 255) {
        return; // Cancel clicked
    }

    if (choice == 2) {
        tableView.clearAll(false);
    }

    for (int i = 0; i < row.size(); i++) {
        ValueMetaInterface v = row.getValueMeta(i);

        boolean add = true;

        if (choice == 0) { // hang on, see if it's not yet in the table view

            if (keys.indexOf(v.getName()) >= 0) {
                add = false;
            }
        }

        if (add) {
            TableItem tableItem = new TableItem(table, SWT.NONE);

            for (int aNameColumn : nameColumn) {
                tableItem.setText(aNameColumn, Const.NVL(v.getName(), ""));
            }
            if (validSchema && !wCreateSchemaFile.getSelection()) {
                for (int anAvroNameColumn : avroNameColumn) {
                    for (int o = 0; o < avroFieldNames.length; o++) {
                        String fieldName = avroFieldNames[o];
                        String matchName = fieldName;
                        if (fieldName != null && fieldName.startsWith("$.")) {
                            matchName = fieldName.substring(2);
                        }
                        if (matchName.equalsIgnoreCase(Const.NVL(v.getName(), ""))) {
                            if (fieldName != null && fieldName.length() > 0) {
                                fieldName = "$." + matchName;
                            }
                            tableItem.setText(anAvroNameColumn, Const.NVL(fieldName, ""));
                            try {

                                Schema fieldSchema = getFieldSchema(fieldName);
                                String[] avroType = AvroOutputField.mapAvroType(fieldSchema,
                                        fieldSchema.getType());
                                if (avroType.length > 0) {
                                    for (int anAvroTypeColumn : avroTypeColumn) {
                                        tableItem.setText(anAvroTypeColumn, avroType[0]);
                                    }
                                }
                            } catch (Exception ex) {
                            }
                            break;
                        }
                    }
                }
            } else if (wCreateSchemaFile.getSelection()) {
                for (int aNameColumn : nameColumn) {
                    tableItem.setText(aNameColumn, Const.NVL(v.getName(), ""));
                }

                String avroName = v.getName();
                if (avroName != null && avroName.length() > 0) {
                    avroName = "$." + avroName;
                }
                for (int anAvroNameColumn : avroNameColumn) {
                    tableItem.setText(anAvroNameColumn, Const.NVL(avroName, ""));
                }

                String avroType = AvroOutputField
                        .getAvroTypeDesc(AvroOutputField.getDefaultAvroType(v.getType()));
                for (int anAvroTypeColumn : avroTypeColumn) {
                    tableItem.setText(anAvroTypeColumn, Const.NVL(avroType, ""));
                }
            }

            if (listener != null) {
                if (!listener.tableItemInserted(tableItem, v)) {
                    tableItem.dispose(); // remove it again
                }
            }
        }
    }
    tableView.removeEmptyRows();
    tableView.setRowNums();
    tableView.optWidth(true);
}

From source file:org.openbi.kettle.plugins.parquetoutput.ParquetOutputDialog.java

License:Apache License

public void getFieldsFromPrevious(RowMetaInterface row, TableView tableView, int keyColumn, int[] nameColumn,
        int[] pathColumn, TableItemInsertListener listener) {
    if (row == null || row.size() == 0) {
        return; // nothing to do
    }/*from w w w  .  ja  v a2 s .co  m*/

    Table table = tableView.table;

    // get a list of all the non-empty keys (names)
    //
    List<String> keys = new ArrayList<String>();
    for (int i = 0; i < table.getItemCount(); i++) {
        TableItem tableItem = table.getItem(i);
        String key = tableItem.getText(keyColumn);
        if (!Const.isEmpty(key) && keys.indexOf(key) < 0) {
            keys.add(key);
        }
    }

    int choice = 0;

    if (keys.size() > 0) {
        // Ask what we should do with the existing data in the step.
        //
        MessageDialog md = new MessageDialog(tableView.getShell(),
                BaseMessages.getString(PKG, "BaseStepDialog.GetFieldsChoice.Title"), // "Warning!"
                null,
                BaseMessages.getString(
                        PKG, "BaseStepDialog.GetFieldsChoice.Message", "" + keys.size(), "" + row.size()),
                MessageDialog.WARNING,
                new String[] { BaseMessages.getString(PKG, "BaseStepDialog.AddNew"),
                        BaseMessages.getString(PKG, "BaseStepDialog.Add"),
                        BaseMessages.getString(PKG, "BaseStepDialog.ClearAndAdd"),
                        BaseMessages.getString(PKG, "BaseStepDialog.Cancel"), },
                0);
        MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        int idx = md.open();
        choice = idx & 0xFF;
    }

    if (choice == 3 || choice == 255) {
        return; // Cancel clicked
    }

    if (choice == 2) {
        tableView.clearAll(false);
    }

    for (int i = 0; i < row.size(); i++) {
        ValueMetaInterface v = row.getValueMeta(i);

        boolean add = true;

        if (choice == 0) { // hang on, see if it's not yet in the table view

            if (keys.indexOf(v.getName()) >= 0) {
                add = false;
            }
        }

        if (add) {
            TableItem tableItem = new TableItem(table, SWT.NONE);

            for (int aNameColumn : nameColumn) {
                tableItem.setText(aNameColumn, Const.NVL(v.getName(), ""));
            }

            for (int aTokenNameColumn : pathColumn) {
                tableItem.setText(aTokenNameColumn, Const.NVL(v.getName(), ""));
            }

            if (listener != null) {
                if (!listener.tableItemInserted(tableItem, v)) {
                    tableItem.dispose(); // remove it again
                }
            }
        }
    }
    tableView.removeEmptyRows();
    tableView.setRowNums();
    tableView.optWidth(true);
}

From source file:org.openbi.kettle.plugins.tableauDataExtract.TDEOutputDialog.java

License:Apache License

private void ok() {
    if (Const.isEmpty(wStepname.getText()))
        return;//from   w w  w . j a  va2 s. c  om

    stepname = wStepname.getText(); // return value

    getInfo(input);

    if ("Y".equalsIgnoreCase(props.getCustomParameter("TABLEAU_OUTPUT_WINDOWS_WARNING", "Y"))) {
        MessageDialogWithToggle md = new MessageDialogWithToggle(shell,
                BaseMessages.getString(PKG, "TDEOutput.TDEWindowsWarning.DialogTitle"), null,
                BaseMessages.getString(PKG, "TDEOutput.TDEWindowsWarning.DialogMessage", Const.CR) + Const.CR,
                MessageDialog.WARNING,
                new String[] { BaseMessages.getString(PKG, "TDEOutput.TDEWindowsWarning.Option1") }, 0,
                BaseMessages.getString(PKG, "TDEOutput.TDEWindowsWarning.Option2"),
                "N".equalsIgnoreCase(props.getCustomParameter("TABLEAU_OUTPUT_WINDOWS_WARNING", "Y")));
        MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
        md.open();
        props.setCustomParameter("TABLEAU_OUTPUT_WINDOWS_WARNING", md.getToggleState() ? "N" : "Y");
        props.saveProps();
    }

    dispose();
}