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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

From source file:de.anbos.eclipse.easyshell.plugin.preferences.CommandPage.java

License:Open Source License

private void removeDialog() {
    // get the selected commands and referenced menus as lists
    List<CommandData> commands = new ArrayList<CommandData>();
    List<MenuData> menus = new ArrayList<MenuData>();
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    Iterator<?> elements = selection.iterator();
    while (elements.hasNext()) {
        CommandData data = (CommandData) elements.next();
        commands.add(data);//  ww  w. j a v a2s .co m
        List<MenuData> menusForOne = MenuDataStore.instance().getRefencedBy(data.getId());
        menus.addAll(menusForOne);
    }
    // ask user
    String commandNames = "";
    PresetType type = PresetType.presetUnknown;
    for (CommandData command : commands) {
        if (type == PresetType.presetUnknown) {
            type = command.getPresetType();
        }
        commandNames += command.getCommandAsComboName() + "\n";
    }
    String title = null;
    String question = null;
    if (type == PresetType.presetPluginAndUser) {
        title = Activator.getResourceString("easyshell.command.page.dialog.remove.user.title");
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.command.page.dialog.remove.user.question"),
                commandNames);
    } else {
        title = Activator.getResourceString("easyshell.command.page.dialog.remove.title");
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.command.page.dialog.remove.question"), commandNames);
    }
    int dialogImageType = MessageDialog.QUESTION;
    if (menus.size() > 0) {
        dialogImageType = MessageDialog.WARNING;
        String menuNames = "";
        for (MenuData menu : menus) {
            menuNames += menu.getNameExpanded() + "\n";
        }
        if (type == PresetType.presetPluginAndUser) {
            title = Activator.getResourceString("easyshell.command.page.dialog.remove.menu.user.title");
            question = MessageFormat.format(
                    Activator.getResourceString("easyshell.command.page.dialog.remove.menu.user.question"),
                    commandNames, menuNames);
        } else {
            title = Activator.getResourceString("easyshell.command.page.dialog.remove.menu.title");
            question = MessageFormat.format(
                    Activator.getResourceString("easyshell.command.page.dialog.remove.menu.question"),
                    commandNames, menuNames);
        }
    }
    MessageDialog dialog = new MessageDialog(null, title, null, question, dialogImageType,
            new String[] { "Yes", "No" }, 1); // no is the default
    int result = dialog.open();
    if (result == 0) {
        if (menus.size() >= 0 && type == PresetType.presetUser) {
            for (MenuData menu : menus) {
                MenuDataStore.instance().delete(menu);
            }
            //MenuDataStore.instance().save();
        }
        for (CommandData command : commands) {
            if (command.getPresetType() == PresetType.presetUser) {
                CommandDataStore.instance().delete(command);
            } else if (command.getPresetType() == PresetType.presetPluginAndUser) {
                command.removeUserData();
                CommandDataStore.instance().replace(command);
            }
        }
        tableViewer.refresh();
    }
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.Initializer.java

License:Open Source License

private int migrate_check_pref_and_ask_user(IPreferenceStore store, Version version, List<String> prefList,
        int migrateState) {
    // if cancel or no just skip this time
    if (migrateState == 1 || migrateState == 2) {
        return migrateState;
    }/*from  w w w  .j a  va2s .c  om*/
    boolean migrationPossible = false;
    for (String pref : prefList) {
        if (!store.isDefault(pref)) {
            migrationPossible = true;
            break;
        }
    }
    if (migrationPossible) {
        // ask user if not already asked and said yes
        if (migrateState != 0) {
            String title = Activator.getResourceString("easyshell.plugin.name");
            String question = MessageFormat.format(Activator.getResourceString("easyshell.question.migrate"),
                    version.getName());
            MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.QUESTION,
                    new String[] { "Yes", "No", "Cancel" }, 0); // no is the default
            migrateState = dialog.open();
        }
    }
    return migrateState;
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.MenuDataDialog.java

License:Open Source License

private void removeDialog() {
    // get the selected commands and referenced menus as lists
    List<CommandData> commands = new ArrayList<CommandData>();
    List<MenuData> menus = new ArrayList<MenuData>();
    // get the selected
    int index = commandCombo.getSelectionIndex();
    CommandData data = cmdList.get(index);
    commands.add(data);/*from w  w w  .j  ava2s  .  c o  m*/
    // get referenced menus and remove the the actual menus
    menus.addAll(MenuDataStore.instance().getRefencedBy(data.getId()));
    menus.remove(this.menuData);
    // ask user
    String commandNames = commandCombo.getItem(index);
    String title = null;
    String question = null;
    if (data.getPresetType() == PresetType.presetPluginAndUser) {
        title = Activator.getResourceString("easyshell.menu.editor.dialog.title.user.remove");
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.menu.editor.dialog.question.user.remove"), commandNames);
    } else {
        title = Activator.getResourceString("easyshell.menu.editor.dialog.title.remove");
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.menu.editor.dialog.question.remove"), commandNames);
    }
    int dialogImageType = MessageDialog.QUESTION;
    if (menus.size() > 0) {
        dialogImageType = MessageDialog.WARNING;
        String menuNames = "";
        for (MenuData menu : menus) {
            menuNames += menu.getNameExpanded() + "\n";
        }
        if (data.getPresetType() == PresetType.presetPluginAndUser) {
            title = Activator.getResourceString("easyshell.menu.editor.dialog.title.remove.user.menu");
            question = MessageFormat.format(
                    Activator.getResourceString("easyshell.menu.editor.dialog.question.remove.user.menu"),
                    commandNames, menuNames);
        } else {
            title = Activator.getResourceString("easyshell.menu.editor.dialog.title.remove.menu");
            question = MessageFormat.format(
                    Activator.getResourceString("easyshell.menu.editor.dialog.question.remove.menu"),
                    commandNames, menuNames);
        }
    }
    MessageDialog dialog = new MessageDialog(null, title, null, question, dialogImageType,
            new String[] { "Yes", "No" }, 1); // no is the default
    int result = dialog.open();
    if (result == 0) {
        for (MenuData menu : menus) {
            MenuDataStore.instance().delete(menu);
        }
        removeCommand(index, data);
        refreshCommandCombo();
    }
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.MenuDataDialog.java

License:Open Source License

private boolean validateValues() {

    String title = Activator.getResourceString("easyshell.menu.editor.dialog.error.incompletedata.title");

    // check type
    if ((commandCombo.getText() == null) || (commandCombo.getText().length() <= 0)) {
        MessageDialog.openError(getShell(), title,
                Activator.getResourceString("easyshell.menu.editor.dialog.error.type.text"));
        return false;
    }//from  ww  w.  ja va 2s. c  o  m

    boolean valid = true;

    // check name
    String text = Activator.getResourceString("easyshell.menu.editor.dialog.error.text.name");
    if ((namePatternText.getText() == null) || (namePatternText.getText().length() <= 0)) {
        valid = false;
    }

    // show error message
    if (!valid) {
        MessageDialog.openError(getShell(), title, text);
    } else {
        int index = commandCombo.getSelectionIndex();
        CommandData data = cmdList.get(index);
        List<MenuData> menus = MenuDataStore.instance().getRefencedBy(data.getId());
        menus.remove(this.menuData);
        if (menus.size() > 0) {
            title = Activator.getResourceString("easyshell.menu.editor.dialog.title.duplicate");
            String commandNames = commandCombo.getItem(index);
            String menuNames = "";
            for (MenuData menu : menus) {
                menuNames += menu.getNameExpanded() + "\n";
            }
            String question = MessageFormat.format(
                    Activator.getResourceString("easyshell.menu.editor.dialog.question.duplicate"),
                    commandNames, menuNames);
            MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.WARNING,
                    new String[] { "Yes", "No" }, 1); // no is the default
            int result = dialog.open();
            if (result != 0) {
                valid = false;
            }
        }
    }

    return valid;
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.MenuPage.java

License:Open Source License

@Override
public boolean performOk() {
    boolean save = true;
    if (!MenuDataStore.instance().isMigrated()) {
        String title = Activator.getResourceString("easyshell.menu.page.dialog.migration.title");
        String question = Activator.getResourceString("easyshell.menu.page.dialog.migration.question");
        MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.WARNING,
                new String[] { "Yes", "No" }, 1); // no is the default
        int result = dialog.open();
        if (result == 0) {
            MenuDataStore.instance().setMigrated(true);
        } else {//  www.  j  av a 2 s  .co m
            save = false;
        }
    }
    if (save) {
        CommandDataStore.instance().save();
        MenuDataStore.instance().save();
    }
    return save;
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.MenuPage.java

License:Open Source License

@Override
protected void performDefaults() {
    String title = Activator.getResourceString("easyshell.menu.page.dialog.defaults.title");
    String question = Activator.getResourceString("easyshell.menu.page.dialog.defaults.question");
    MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.WARNING,
            new String[] { "Yes", "No" }, 1); // no is the default
    int result = dialog.open();
    if (result == 0) {
        MenuDataStore.instance().loadDefaults();
        refreshTableViewer();/*from   w  w w  .j  ava2  s .c o m*/
    }
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.MenuPage.java

License:Open Source License

private void removeDialog() {
    // get the selected menus as lists
    List<MenuData> menus = new ArrayList<MenuData>();
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    Iterator<?> elements = selection.iterator();
    while (elements.hasNext()) {
        MenuData data = (MenuData) elements.next();
        menus.add(data);/*from ww  w .  j  av  a  2  s  .  c  o m*/
    }
    if (menus.size() > 0) {
        String title = Activator.getResourceString("easyshell.menu.page.dialog.remove.title");
        String menuNames = "";
        for (MenuData menu : menus) {
            menuNames += menu.getNameExpanded() + "\n";
        }
        String question = MessageFormat
                .format(Activator.getResourceString("easyshell.menu.page.dialog.remove.question"), menuNames);
        MessageDialog dialog = new MessageDialog(null, title, null, question, MessageDialog.QUESTION,
                new String[] { "Yes", "No" }, 1); // no is the default
        int result = dialog.open();
        if (result == 0) {
            for (MenuData menu : menus) {
                MenuDataStore.instance().delete(menu);
            }
            refreshTableViewer();
        }
    }
}

From source file:de.blizzy.backup.BackupApplication.java

License:Open Source License

@Override
public Object start(IApplicationContext context) {
    display = Display.getDefault();//from   w w  w . j a v  a  2  s.  co  m

    boolean restartNecessary = false;

    File runLockFile = new File(BackupPlugin.getDefault().getStateLocation().toFile(), "runLock"); //$NON-NLS-1$
    RunLock runLock = new RunLock(runLockFile);
    if (runLock.tryLock()) {
        setupDefaultPreferences();

        Image image16 = AbstractUIPlugin.imageDescriptorFromPlugin(BackupPlugin.ID, "etc/logo/logo_16.png") //$NON-NLS-1$
                .createImage(display);
        Image image32 = AbstractUIPlugin.imageDescriptorFromPlugin(BackupPlugin.ID, "etc/logo/logo_32.png") //$NON-NLS-1$
                .createImage(display);
        Image image48 = AbstractUIPlugin.imageDescriptorFromPlugin(BackupPlugin.ID, "etc/logo/logo_48.png") //$NON-NLS-1$
                .createImage(display);
        windowImages = new Image[] { image16, image32, image48 };

        settingsManager = new SettingsManager();
        settingsManager.addListener(new ISettingsListener() {
            @Override
            public void settingsChanged() {
                if (backupRun == null) {
                    scheduleBackupRun(false);
                }
            }
        });

        timer = new Timer();

        scheduleBackupRun(false);

        trayIcon = new TrayIcon(display);

        context.applicationRunning();

        if (!BackupPlugin.getDefault().isHidden()) {
            showShell();
        }

        try {
            Shell shell = (backupShell != null) ? backupShell.getShell() : null;
            if (new Updater(false, false).update(shell)) {
                running = false;
                restartNecessary = true;
            }
        } catch (Throwable e) {
            BackupPlugin.getDefault().logError("error while updating application", e); //$NON-NLS-1$
        }

        while (running && !display.isDisposed()) {
            try {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            } catch (RuntimeException e) {
                BackupPlugin.getDefault().logError("error in event loop", e); //$NON-NLS-1$
            }
        }

        trayIcon.dispose();

        timer.cancel();
        timer = null;

        image16.dispose();
        image32.dispose();
        image48.dispose();

        if (backupRun != null) {
            backupRun.stopBackupAndWait();
        }
    } else {
        new MessageDialog(null, Messages.Title_ProgramRunning, null, Messages.ProgramRunning,
                MessageDialog.ERROR, new String[] { IDialogConstants.CLOSE_LABEL }, 0).open();
    }

    return restartNecessary ? EXIT_RESTART : EXIT_OK;
}

From source file:de.blizzy.backup.BackupShell.java

License:Open Source License

BackupShell(Display display) {
    shell = new Shell(display, SWT.SHELL_TRIM ^ SWT.MAX);
    shell.setText(Messages.Title_BlizzysBackup);
    shell.setImages(BackupApplication.getWindowImages());

    GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 20;//from ww w  .java2s  .co m
    layout.marginHeight = 20;
    layout.verticalSpacing = 15;
    shell.setLayout(layout);

    Composite logoAndHeaderComposite = new Composite(shell, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 15;
    logoAndHeaderComposite.setLayout(layout);

    Canvas logoCanvas = new Canvas(logoAndHeaderComposite, SWT.DOUBLE_BUFFERED);
    logoCanvas.addPaintListener(new PaintListener() {
        @Override
        public void paintControl(PaintEvent e) {
            Image image = BackupPlugin.getDefault().getImageDescriptor("etc/logo/logo_48.png") //$NON-NLS-1$
                    .createImage(e.display);
            e.gc.drawImage(image, 0, 0);
            image.dispose();
        }
    });
    GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
    gd.widthHint = 48;
    gd.heightHint = 48;
    logoCanvas.setLayoutData(gd);

    Link headerText = new Link(logoAndHeaderComposite, SWT.NONE);
    headerText.setText(NLS.bind(Messages.Version, BackupPlugin.VERSION, BackupPlugin.COPYRIGHT_YEARS));

    Composite buttonsComposite = new Composite(shell, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 10;
    layout.verticalSpacing = 15;
    buttonsComposite.setLayout(layout);
    buttonsComposite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));

    FontData[] fontDatas = buttonsComposite.getFont().getFontData();
    for (FontData fontData : fontDatas) {
        fontData.setHeight((int) (fontData.getHeight() * 1.5d));
    }
    final Font bigFont = new Font(display, fontDatas);

    Point extent = getMaxTextExtent(display, bigFont, Messages.Button_Settings, Messages.Button_Restore,
            Messages.Button_BackupNow);

    Button settingsButton = new Button(buttonsComposite, SWT.PUSH);
    settingsButton.setText(Messages.Button_Settings);
    settingsButton.setFont(bigFont);
    gd = new GridData(SWT.FILL, SWT.FILL, false, true);
    gd.widthHint = (int) (extent.x * 1.6d);
    gd.heightHint = extent.y * 2;
    settingsButton.setLayoutData(gd);

    Label label = new Label(buttonsComposite, SWT.NONE);
    label.setText(Messages.ModifyBackupSettings);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));

    restoreButton = new Button(buttonsComposite, SWT.PUSH);
    restoreButton.setText(Messages.Button_Restore);
    restoreButton.setFont(bigFont);
    gd = new GridData(SWT.FILL, SWT.FILL, false, true);
    gd.widthHint = (int) (extent.x * 1.6d);
    gd.heightHint = extent.y * 2;
    restoreButton.setLayoutData(gd);
    updateRestoreButton();

    label = new Label(buttonsComposite, SWT.NONE);
    label.setText(Messages.RestoreFromBackup);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));

    backupNowButton = new Button(buttonsComposite, SWT.PUSH);
    backupNowButton.setText(Messages.Button_BackupNow);
    backupNowButton.setFont(bigFont);
    gd = new GridData(SWT.FILL, SWT.FILL, false, true);
    gd.widthHint = (int) (extent.x * 1.6d);
    gd.heightHint = extent.y * 2;
    backupNowButton.setLayoutData(gd);
    updateBackupNowButton();

    label = new Label(buttonsComposite, SWT.NONE);
    label.setText(Messages.RunBackupNow);
    label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));

    if (BackupPlugin.getDefault().isCheckGui()) {
        checkButton = new Button(buttonsComposite, SWT.PUSH);
        checkButton.setText(Messages.Button_Check);
        checkButton.setFont(bigFont);
        gd = new GridData(SWT.FILL, SWT.FILL, false, true);
        gd.widthHint = (int) (extent.x * 1.6d);
        gd.heightHint = extent.y * 2;
        checkButton.setLayoutData(gd);
        updateCheckButton();

        label = new Label(buttonsComposite, SWT.NONE);
        label.setText(Messages.CheckBackup);
        label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
    }

    Composite progressStatusComposite = new Composite(shell, SWT.NONE);
    layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    progressStatusComposite.setLayout(layout);
    progressStatusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    progressComposite = new Composite(progressStatusComposite, SWT.NONE);
    layout = new GridLayout(3, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    progressComposite.setLayout(layout);
    progressComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    progressBar = new ProgressBar(progressComposite, SWT.HORIZONTAL | SWT.SMOOTH);
    progressBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    progressBar.setMinimum(0);
    updateProgressVisibility();

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);

    pauseAction = new Action(Messages.Button_PauseBackup, IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            if (backupRun != null) {
                backupRun.setPaused(pauseAction.isChecked());
            }
        }
    };
    ImageDescriptor imgDesc = BackupPlugin.getDefault().getImageDescriptor("etc/icons/pause.gif"); //$NON-NLS-1$
    pauseAction.setImageDescriptor(imgDesc);
    pauseAction.setToolTipText(Messages.Button_PauseBackup);
    toolBarManager.add(pauseAction);

    stopAction = new Action() {
        @Override
        public void run() {
            if (backupRun != null) {
                pauseAction.setChecked(false);
                pauseAction.setEnabled(false);
                stopAction.setEnabled(false);
                backupRun.stopBackup();
            }
        }
    };
    imgDesc = BackupPlugin.getDefault().getImageDescriptor("etc/icons/stop.gif"); //$NON-NLS-1$
    stopAction.setImageDescriptor(imgDesc);
    stopAction.setToolTipText(Messages.Button_StopBackup);
    toolBarManager.add(stopAction);

    ToolBar toolBar = toolBarManager.createControl(progressComposite);
    toolBar.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));

    statusLabel = new Link(progressStatusComposite, SWT.NONE);
    statusLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    updateStatusLabel(null);

    shell.pack();

    headerText.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            new LicenseDialog(shell).open();
        }
    });

    settingsButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            editSettings();
        }
    });

    restoreButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            restore();
        }
    });

    backupNowButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            BackupApplication.scheduleBackupRun(true);
        }
    });

    if (checkButton != null) {
        checkButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                BackupApplication.runCheck();
            }
        });
    }

    statusLabel.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.text.equals("errors")) { //$NON-NLS-1$
                showErrors();
            }
        }
    });

    shell.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            bigFont.dispose();
        }
    });

    shell.addShellListener(new ShellAdapter() {
        @Override
        public void shellClosed(ShellEvent e) {
            MessageDialog dlg = new MessageDialog(shell, Messages.Title_ExitApplication, null,
                    Messages.ExitApplication, MessageDialog.CONFIRM,
                    new String[] { Messages.Button_Exit, Messages.Button_MinimizeOnly }, 1);
            if (dlg.open() == 0) {
                BackupApplication.quit();
            } else {
                e.doit = false;
                BackupApplication.hideShell();
            }
        }

        @Override
        public void shellIconified(ShellEvent e) {
            e.doit = false;
            BackupApplication.hideShell();
        }
    });

    shell.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
            handleDispose();
        }
    });

    BackupApplication.getSettingsManager().addListener(settingsListener);

    settingsButton.forceFocus();
}

From source file:de.fhdo.elexis.perspective.handler.ImportHandler.java

License:Open Source License

@Override
@SuppressWarnings("all")
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow mainWindow = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    PerspectiveRegistry perspRegistry = (PerspectiveRegistry) WorkbenchPlugin.getDefault()
            .getPerspectiveRegistry();//from w  w w . j  a v  a2 s . co  m
    String importMessage = ""; //$NON-NLS-1$

    //
    // Open a FileDialog to select the .xml files with stored perspectives
    // Only display .xml Files to select
    //
    FileDialog diag = new FileDialog(mainWindow.getShell(), SWT.MULTI);

    String[] filterNames = { "XML" };//$NON-NLS-1$
    String[] filterExtensions = { "*.xml" };//$NON-NLS-1$

    diag.setFilterNames(filterNames);
    diag.setFilterExtensions(filterExtensions);

    if (diag.open() == null)
        return null;

    //
    // Since it is possible to select multiple perspectives to be restored we have to iterate
    // over the selected files
    //
    for (String file : diag.getFileNames()) {
        String filename = diag.getFilterPath() + File.separator + file;
        FileReader reader;
        XMLMemento memento = null;

        try {
            reader = new FileReader(new File(filename));
            memento = XMLMemento.createReadRoot(reader);
            PerspectiveDescriptor newPersp = new PerspectiveDescriptor(null, null, null);

            //
            // Get the label and the ID of the stored perspective
            //
            String label = memento.getChild("descriptor").getString("label"); //$NON-NLS-1$ //$NON-NLS-2$
            String id = memento.getChild("descriptor").getString("id"); //$NON-NLS-1$ //$NON-NLS-2$

            //
            // Find the perspective by label within the preference store
            //
            PerspectiveDescriptor pd = (PerspectiveDescriptor) perspRegistry.findPerspectiveWithLabel(label);

            String[] buttonLabels = { Messages.ImportHandler_Abort, Messages.ImportHandler_Overwrite,
                    Messages.ImportHandler_Rename };

            while (pd != null) {

                //
                // If pd != null the perspective is already present in the preference store
                // though we have to store it with a different name
                //
                String notDeleted = "";//$NON-NLS-1$
                String dialogMessage = String.format(Messages.ImportHandler_Name_Import_Already_Exists, label);
                MessageDialog mesDiag = new MessageDialog(mainWindow.getShell(),
                        Messages.ImportHandler_OverWrite_Perspective, null, dialogMessage, 0, buttonLabels, 0);
                int ergMesDiag = mesDiag.open();

                if (ergMesDiag == 0) // Cancel was pressed
                    return null;
                else if (ergMesDiag == 1) // Overwrite was pressed
                {
                    perspRegistry.deletePerspective(pd);
                    PerspectiveDescriptor pd2 = (PerspectiveDescriptor) perspRegistry
                            .findPerspectiveWithLabel(label);

                    //
                    // If the perspective could not be deleted, the user have to choose another
                    // name
                    //
                    if (pd2 != null) {
                        notDeleted = Messages.ImportHandler_Cannot_Overwrite_Perspective;
                        ergMesDiag = 2;
                    }

                    //
                    // After the Perspective has been deleted the descriptor has to be null
                    //
                    pd = null;
                }

                if (ergMesDiag == 2) // Rename was pressed
                {

                    String dialogMessageOverride = notDeleted
                            + Messages.ImportHandler_Choose_new_name_for_Perspective;
                    ;
                    InputDialog inputDiag = new InputDialog(mainWindow.getShell(),
                            Messages.ImportHandler_Rename_Perspective, dialogMessageOverride, null, null);

                    inputDiag.open();

                    String[] idsplit = id.split("\\.");//$NON-NLS-1$
                    System.out.println("ID: " + idsplit.length);//$NON-NLS-1$
                    id = "";//$NON-NLS-1$
                    label = inputDiag.getValue();

                    for (int i = 0; i < idsplit.length - 1; i++) {
                        id += idsplit[i] + ".";//$NON-NLS-1$
                    }

                    id += label;

                    //
                    // Create a new perspective with the new name
                    //
                    newPersp = new PerspectiveDescriptor(id, label, pd);

                    pd = (PerspectiveDescriptor) perspRegistry.findPerspectiveWithLabel(label);
                }
            }

            memento.getChild("descriptor").putString("label", label); //$NON-NLS-1$ //$NON-NLS-2$
            memento.getChild("descriptor").putString("id", id);//$NON-NLS-1$ //$NON-NLS-2$

            newPersp.restoreState(memento);

            reader.close();

            //
            // Save the new generated perspective in the preference store
            //
            perspRegistry.saveCustomPersp(newPersp, memento);

            importMessage += String.format(Messages.ImportHandler_Saved_As, file, newPersp.getLabel());

        } catch (WorkbenchException e) {
            unableToLoadPerspective(e.getStatus());
        } catch (IOException e) {
            unableToLoadPerspective(null);
        }
    }

    MessageDialog.openInformation(mainWindow.getShell(), Messages.ImportHandler_Successfully_Imported,
            Messages.ImportHandler_Imported_perspectives_successfully + importMessage);

    return null;
}