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:com.nokia.carbide.cpp.uiq.ui.vieweditor.CommandsPage.java

License:Open Source License

/**
 * This code was taken from the EventCommands class. It has the validations in case the code
 * doesn't exist.//  www  . java2s.com
 * @param binding
 * @param isNewBinding
 */
private void navigateToHandlerCode(IEventBinding binding, boolean isNewBinding) {
    IEventDescriptor eventDescriptor = binding.getEventDescriptor();
    IStatus status = eventDescriptor.gotoHandlerCode(binding, isNewBinding);
    if (status != null) {
        if (!isNewBinding) {
            // Hmm, an error.  It could be the data model was not saved.
            // It may just be a problem in the component's sourcegen, hence
            // the fallthrough to the descriptive error later.
            MessageDialog dialog = new MessageDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.getString("CommandsPage.Error"), null, //$NON-NLS-1$
                    Messages.getString("CommandsPage.NoEventHandlerFound"), //$NON-NLS-1$
                    MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, //$NON-NLS-1$ //$NON-NLS-2$
                    0);
            int result = dialog.open();
            if (result == MessageDialog.OK) {
                if (ViewEditorUtils.saveDataModel(editor)) {
                    status = eventDescriptor.gotoHandlerCode(binding, isNewBinding);
                }
            }
        }
        if (status != null) {
            Logging.log(UIDesignerPlugin.getDefault(), status);
            Logging.showErrorDialog(Messages.getString("CommandsPage.CouldNotNavigate"), null, status); //$NON-NLS-1$
        }
    }

}

From source file:com.nokia.carbide.search.system.internal.ui.text.ReplaceDialog2.java

License:Open Source License

private int askForSkip(final IFileStore file) {

    String message = Messages.format(SearchMessages.ReadOnlyDialog_message, getFullPath(file).toString());
    String[] buttonLabels = null;
    boolean showSkip = countResources() > 1;
    if (showSkip) {
        String skipLabel = SearchMessages.ReadOnlyDialog_skipFile;
        String skipAllLabel = SearchMessages.ReadOnlyDialog_skipAll;
        buttonLabels = new String[] { skipLabel, skipAllLabel, IDialogConstants.CANCEL_LABEL };
    } else {//  ww w.  j  a  va2 s  . c  o m
        buttonLabels = new String[] { IDialogConstants.CANCEL_LABEL };

    }

    MessageDialog msd = new MessageDialog(getShell(), getShell().getText(), null, message, MessageDialog.ERROR,
            buttonLabels, 0);
    int rc = msd.open();
    switch (rc) {
    case 0:
        return showSkip ? SKIP_FILE : CANCEL;
    case 1:
        return SKIP_ALL;
    default:
        return CANCEL;
    }
}

From source file:com.nokia.s60tools.analyzetool.global.Util.java

License:Open Source License

/**
 * Opens confirmation Dialog.//from  w  w  w.ja  va  2 s  . c o m
 * 
 * @param text
 *            Dialog info text
 * @return int User selected index
 */
public static int openConfirmationDialogWithCancel(final String text) {

    Activator.getDefault().getWorkbench().getDisplay().syncExec(new Runnable() {
        public void run() {

            String[] labels = new String[3];
            labels[0] = "Yes";
            labels[1] = "No";
            labels[2] = "Cancel";
            MessageDialog mDialog = new MessageDialog(new Shell(), Constants.ANALYZE_TOOL_TITLE, null, text, 0,
                    labels, 0);
            mDialog.open();
            mDialog.create();
            retValue = mDialog.getReturnCode();
        }
    });
    return retValue;
}

From source file:com.nokia.s60tools.compatibilityanalyser.ui.dialogs.BaselineEditor.java

License:Open Source License

public void widgetSelected(SelectionEvent e) {

    if (e.widget == saveBtn) {
        if (profileCmb.getText().length() == 0) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(),
                    Messages.getString("BaselineEditor.Error"), //$NON-NLS-1$
                    Messages.getString("BaselineEditor.ProfileNameMustNotBeEmpty")); //$NON-NLS-1$
            return;
        }//from   w  ww  .  j  ava  2  s .co m

        String profileName = profileCmb.getText();
        Object profile = BaselineProfileUtils.getBaselineProfileData(profileName);
        if (profile instanceof BaselineProfile && ((BaselineProfile) profile).isPredefined()) {
            prevData.saveValue(SavingUserData.ValueTypes.PROFILENAME, profileCmb.getText());
            shell.getParent().dispose();
            return;
        }

        if (isProfileDataCorrect()) {
            if (profileCmb.indexOf(profileCmb.getText()) != -1) {
                String[] str = { Messages.getString("BaselineEditor.Yes"), //$NON-NLS-1$
                        Messages.getString("BaselineEditor.69"), Messages.getString("BaselineEditor.No") }; //$NON-NLS-1$ //$NON-NLS-2$
                MessageDialog dlg = new MessageDialog(Display.getCurrent().getActiveShell(),
                        Messages.getString("BaselineEditor.Confirmation"), null, //$NON-NLS-1$
                        Messages.getString("BaselineEditor.ThisProfileAlreadyExists"), MessageDialog.QUESTION, //$NON-NLS-1$
                        str, 0);
                dlg.create();
                int res = dlg.open();
                if (res == 0) {
                    saveProfile();
                    prevData.saveValue(SavingUserData.ValueTypes.PROFILENAME, profileCmb.getText());
                }
            } else {
                saveProfile();
                prevData.saveValue(SavingUserData.ValueTypes.PROFILENAME, profileCmb.getText());
            }

            //Delete the project, if the profile is created by using blf.inf 
            try {
                if (selectedProj != null) {
                    prevData.saveValue(SavingUserData.ValueTypes.BLDINF_PATH, bldInfPath.getText());
                    if (selectedProj.exists() && projDeletionReq) {
                        selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                        projDeletionReq = false;
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            shell.getParent().dispose();
        }
    } else if (e.widget == deleteBtn) {
        String[] str = { Messages.getString("BaselineEditor.Yes"), Messages.getString("BaselineEditor.No2"),
                Messages.getString("BaselineEditor.Cancel") };
        MessageDialog dlg = new MessageDialog(Display.getCurrent().getActiveShell(),
                Messages.getString("BaselineEditor.Confirmation"), null,
                Messages.getString("BaselineEditor.DoUWantToDeleteTheProfile") + profileCmb.getText() + "'?",
                MessageDialog.QUESTION, str, 0);
        dlg.create();
        int res = dlg.open();
        if (res == 0) {
            BaselineProfileUtils.deleteProfile(profileCmb.getText());
            shell.getParent().dispose();
        }
    } else if (e.widget == cancelBtn) {
        try {
            if (selectedProj != null && selectedProj.exists() && projDeletionReq) {
                selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                projDeletionReq = false;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        shell.getParent().dispose();
    } else if (e.widget == profileCmb) {
        Object obj = BaselineProfileUtils.getBaselineProfileData(profileCmb.getText());
        if (obj instanceof BaselineProfile) {
            BaselineProfile pro = (BaselineProfile) obj;
            if (!pro.isPredefined())
                openBaselineProfileIfExists(profileCmb.getText());
            else {
                if (!pro.isUpdated()) {
                    targetPath = "c:\\apps\\ca-baselines\\" + pro.getProfileName();
                    targetURL = pro.getSdkUrl();

                    IRunnableWithProgress op = new IRunnableWithProgress() {
                        public void run(IProgressMonitor monitor) {
                            if (new File(targetPath).exists())
                                FileMethods.deleteFolder(targetPath);
                            downloadStatus = CompatibilityAnalyserEngine.downloadAndExtractFileFromWebServer(
                                    targetURL, targetPath, CompatibilityAnalyserEngine.ElementTypes.FolderType,
                                    "include", monitor);
                        }
                    };
                    IWorkbench wb = PlatformUI.getWorkbench();
                    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                    Shell shell = win != null ? win.getShell() : null;
                    try {
                        new ProgressMonitorDialog(shell).run(true, true, op);
                    } catch (InvocationTargetException err) {
                        err.printStackTrace();
                    } catch (InterruptedException err) {
                        err.printStackTrace();
                    }

                    if (downloadStatus == null) {
                        File epocRoot = new File(CompatibilityAnalyserEngine.getEpocFolderPath());
                        BaselineProfile profile = (BaselineProfile) obj;
                        profile.setSdkName(profile.getProfileName());
                        profile.setRadio_default_hdr(true);
                        profile.setRadio_dir_hdr(false);
                        profile.setRadio_default_build_target(true);
                        profile.setRadio_build_target(false);
                        profile.setRadio_dir_libs(false);
                        profile.setSdkEpocRoot(
                                FileMethods.appendPathSeparator(epocRoot.getParentFile().getAbsolutePath()));
                        profile.setUpdated(true);
                        BaselineProfileUtils.saveProfileOnFileSystem(profile);
                        openBaselineProfileIfExists(profileCmb.getText());
                        prevData.saveValue(SavingUserData.ValueTypes.PROFILENAME, profile.getProfileName());
                    } else {
                        openBaselineProfileIfExists(null);
                        MessageDialog.openError(this.getShell(), "Compatibility Analyser", downloadStatus);
                        downloadStatus = null;
                    }
                }
                openBaselineProfileIfExists(pro.getProfileName());
            }
        }
        hdrGrp.layout();
        shell.layout();
    } else if (e.widget == sdkCmb) {
        sdkrootLbl.setText(sdkItems[sdkCmb.getSelectionIndex()].getEPOCROOT());
        if (versionCmb
                .indexOf(sdkItems[sdkCmb.getSelectionIndex()].getSDKVersion().toString().substring(0, 3)) != -1)
            versionCmb.select(versionCmb
                    .indexOf(sdkItems[sdkCmb.getSelectionIndex()].getSDKVersion().toString().substring(0, 3)));
        else
            versionCmb.setText(""); //$NON-NLS-1$

        String[] platformsList = CompatibilityAnalyserUtils
                .getPlatformList(sdkItems[sdkCmb.getSelectionIndex()]);

        if (platformsList != null)
            list_build_Config.setItems(platformsList);

        if (list_build_Config.getItemCount() > 0) {
            int i = list_build_Config.indexOf(Messages.getString("BaselineEditor.armv5")); //$NON-NLS-1$
            if (i != -1)
                list_build_Config.select(i);
            else
                list_build_Config.select(0);

            String selected = list_build_Config.getItem(list_build_Config.getSelectionIndex());
            radio_build_target.setText(Messages.getString("BaselineEditor.UseLibrariesUnder") + selected //$NON-NLS-1$
                    + Messages.getString("BaselineEditor.BuildConfig")); //$NON-NLS-1$
        }
        if (infCheck.getSelection() && bldInfPath.getText().length() != 0) {
            String bldPath = bldInfPath.getText();

            File bldFile = new File(bldPath);
            File Project = bldFile.getParentFile().getParentFile();

            userFiles = new ArrayList<File>();
            systemFiles = new ArrayList<File>();

            projName = Project.getName();
            projLocation = Project.getAbsolutePath();

            projExists = false;

            selectedSdk = sdkItems[sdkCmb.getSelectionIndex()];

            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {

                        isCancelled = false;
                        selectedProj = ResourcesPlugin.getWorkspace().getRoot()
                                .getProject("CompatibilityAnalyser_" + projName);
                        if (selectedProj.exists()) {
                            projExists = true;
                        } else {
                            for (IProject wsProj : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
                                projLocation = FileMethods.convertForwardToBackwardSlashes(projLocation);
                                if (FileMethods.convertForwardToBackwardSlashes(wsProj.getLocation().toString())
                                        .equals(projLocation)) {
                                    projExists = true;
                                    selectedProj = wsProj;
                                    break;
                                }
                            }
                        }

                        java.util.List<ISymbianBuildContext> buildList = selectedSdk
                                .getFilteredBuildConfigurations();

                        if (projExists) {
                            monitor.beginTask("Reading system includes using selected SDK Configuration ...",
                                    10);
                            selectedProj.open(null);
                            ICarbideBuildManager buildMgr = CarbideBuilderPlugin.getBuildManager();
                            ICarbideProjectModifier modifier = buildMgr.getProjectModifier(selectedProj);

                            monitor.worked(2);

                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                monitor.done();
                                return;
                            }
                            ICarbideProjectInfo projectInfo = buildMgr.getProjectInfo(selectedProj);
                            ICarbideBuildConfiguration origConf = projectInfo.getDefaultConfiguration();

                            ICarbideBuildConfiguration configTobeSet = null;
                            configTobeSet = modifier.createNewConfiguration(buildList.get(0), true);

                            configTobeSet.saveConfiguration(false);
                            modifier.setDefaultConfiguration(configTobeSet);
                            modifier.saveChanges();

                            monitor.worked(5);
                            if (monitor.isCanceled()) {
                                modifier.setDefaultConfiguration(origConf);
                                modifier.saveChanges();
                                monitor.done();

                                return;
                            }

                            if (projectInfo != null) {
                                EpocEngineHelper.getProjectIncludePaths(projectInfo,
                                        projectInfo.getDefaultConfiguration(), userFiles, systemFiles);
                                getExportPathsAndFiles(projectInfo, userFiles);
                                srcRoots = CompatibilityAnalyserEngine.getIncludesFromSrcFiles(selectedProj)
                                        .toArray(new String[0]);
                            }

                            monitor.worked(8);
                            modifier.setDefaultConfiguration(origConf);
                            modifier.saveChanges();

                            monitor.worked(10);
                            if (monitor.isCanceled())
                                isCancelled = true;
                            monitor.done();
                        } else {
                            monitor.beginTask("Getting system includes using selected SDK Configuration...",
                                    10);
                            selectedProj = ProjectCorePlugin.createProject(projName, projLocation);
                            projDeletionReq = true;

                            monitor.worked(2);

                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                if (selectedProj != null && selectedProj.exists()) {
                                    try {
                                        selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                    } catch (Exception e1) {
                                        e1.printStackTrace();
                                    }
                                }
                                monitor.done();
                                projDeletionReq = false;
                                return;
                            }
                            java.util.List<String> infsList = new ArrayList<String>();

                            ProjectCorePlugin.postProjectCreatedActions(selectedProj, "group/bld.inf",
                                    buildList, infsList, null, null, new NullProgressMonitor());
                            monitor.worked(5);
                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                if (selectedProj != null && selectedProj.exists()) {
                                    try {
                                        selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                    } catch (Exception e1) {
                                        e1.printStackTrace();
                                    }
                                }
                                monitor.done();
                                projDeletionReq = false;
                                return;
                            }
                            ICarbideProjectInfo projInfo = CarbideBuilderPlugin.getBuildManager()
                                    .getProjectInfo(selectedProj);

                            if (projInfo != null) {
                                EpocEngineHelper.getProjectIncludePaths(projInfo,
                                        projInfo.getDefaultConfiguration(), userFiles, systemFiles);
                                getExportPathsAndFiles(projInfo, userFiles);
                                monitor.worked(7);
                                srcRoots = CompatibilityAnalyserEngine.getIncludesFromSrcFiles(selectedProj)
                                        .toArray(new String[0]);

                                monitor.worked(9);
                                if (monitor.isCanceled())
                                    isCancelled = true;
                            }
                            monitor.done();
                        }

                    } catch (CoreException ex) {
                        ex.printStackTrace();
                        try {
                            if (selectedProj != null && selectedProj.exists() && projDeletionReq) {
                                selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                projDeletionReq = false;
                            }
                            return;
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                }

            };

            try {
                new ProgressMonitorDialog(this.shell.getShell()).run(true, true, runnable);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            String[] sysIncludes = new String[systemFiles.size()];
            int s = 0;

            if (isCancelled)
                return;

            for (File f : systemFiles) {
                sysIncludes[s] = f.toString();
                s++;
            }
            if (srcRoots != null && srcRoots.length > 0) {
                forced_hdrs_list.setItems(srcRoots);
            }

            if (userFiles.size() > 0) {
                ArrayList<String> userIncludes = new ArrayList<String>();

                for (int i = 0; i < userFiles.size(); i++) {
                    if (userFiles.get(i).exists())
                        userIncludes
                                .add(FileMethods.convertForwardToBackwardSlashes(userFiles.get(i).toString()));
                }
                Event modEvent = new Event();
                modEvent.type = SWT.Selection;
                radio_Hdr_dir.setSelection(true);
                hdr_dir_list.setItems(userIncludes.toArray(new String[0]));
                hdr_dir_list.select(0);
                radio_Hdr_dir.notifyListeners(SWT.Selection, modEvent);

            }
            if (sysIncludes.length > 0) {
                list_systemInc.setItems(sysIncludes);
                removeBtn_sysIncGrp.setEnabled(true);
                removeAllBtn_sysIncGrp.setEnabled(true);
                list_systemInc.select(0);
            }
            updateButtons();
            return;
        }
    } else if (e.widget == addBtn_hdrGrp) {
        DirectoryDialog dirDlg = new DirectoryDialog(Display.getDefault().getActiveShell());
        String dirName = null;
        if ((dirName = dirDlg.open()) != null) {
            hdr_dir_list.add(dirName);
            hdr_dir_list.select(0);
            updateButtons();
        } else
            return;

    } else if (e.widget == removeBtn_hdrGrp) {
        hdr_dir_list.remove(hdr_dir_list.getSelectionIndices());
        hdr_dir_list.select(0);
        updateButtons();
    } else if (e.widget == removeAllBtn_hdrGrp) {
        hdr_dir_list.removeAll();
        updateButtons();
    } else if (e.widget == addDsoDir_btn) {
        DirectoryDialog dirDlg = new DirectoryDialog(Display.getDefault().getActiveShell());
        String dirName = null;
        if ((dirName = dirDlg.open()) != null) {
            dso_dir_list.add(dirName);
            dso_dir_list.select(0);
            updateButtons();
        } else
            return;
    } else if (e.widget == addDllDir_btn) {
        DirectoryDialog dirDlg = new DirectoryDialog(Display.getDefault().getActiveShell());
        String dirName = null;
        if ((dirName = dirDlg.open()) != null) {
            dll_dir_list.add(dirName);
            dll_dir_list.select(0);
            updateButtons();
        } else
            return;
    } else if (e.widget == removeDsoDir_Btn) {
        dso_dir_list.remove(dso_dir_list.getSelectionIndices());
        dso_dir_list.select(0);
        updateButtons();
    } else if (e.widget == removeDllDir_btn) {
        dll_dir_list.remove(dll_dir_list.getSelectionIndices());
        dll_dir_list.select(0);
        updateButtons();
    } else if (e.widget == removeAllDsoDirs_Btn) {
        dso_dir_list.removeAll();
        updateButtons();
    } else if (e.widget == removeAllDllDir_Btn) {
        dll_dir_list.removeAll();
        updateButtons();
    } else if (e.widget == addBtn_sysIncGrp) {
        DirectoryDialog dirDlg = new DirectoryDialog(Display.getDefault().getActiveShell());
        String dirName = null;
        if ((dirName = dirDlg.open()) != null) {
            list_systemInc.add(dirName);
            list_systemInc.select(0);
            updateButtons();
        } else
            return;

    } else if (e.widget == removeBtn_sysIncGrp) {
        list_systemInc.remove(list_systemInc.getSelectionIndices());
        list_systemInc.select(0);
        updateButtons();
    } else if (e.widget == radio_Hdr_dir) {
        GridData d = (GridData) hdr_dirs_comp.getLayoutData();
        d.exclude = !radio_Hdr_dir.getSelection();
        hdr_dirs_comp.setVisible(radio_Hdr_dir.getSelection());

        hdr_dir_list.setEnabled(radio_Hdr_dir.getSelection());
        addBtn_hdrGrp.setEnabled(radio_Hdr_dir.getSelection());
        updateButtons();
    } else if (e.widget == radio_dir_Libs || e.widget == radio_build_target) {
        //dso_dir_list.setEnabled(radio_dir_Libs.getSelection());

        addDsoDir_btn.setEnabled(radio_dir_Libs.getSelection());
        addDllDir_btn.setEnabled(radio_dir_Libs.getSelection());

        //removeDsoDir_Btn.setEnabled(radio_dir_Libs.getSelection());
        //removeAllDsoDirs_Btn.setEnabled(radio_dir_Libs.getSelection());
        //list_build_Config.setEnabled(!radio_dir_Libs.getSelection());

        GridData data = (GridData) list_build_Config.getLayoutData();
        data.exclude = !radio_build_target.getSelection();
        list_build_Config.setVisible(radio_build_target.getSelection());

        GridData data2 = (GridData) dllPaths_Folder.getLayoutData();
        data2.exclude = !radio_dir_Libs.getSelection();
        dllPaths_Folder.setVisible(radio_dir_Libs.getSelection());

        dllPaths_Folder.getParent().layout(false);

        updateButtons();
    } else if (e.widget == list_build_Config) {
        if (list_build_Config.getSelectionCount() > 1)
            radio_build_target.setText("Use libraries under selected build configurations");
        else {
            String selected = list_build_Config.getItem(list_build_Config.getSelectionIndex());
            radio_build_target.setText(Messages.getString("BaselineEditor.UseLibrariesUnder") + selected //$NON-NLS-1$
                    + Messages.getString("BaselineEditor.BuildConfig")); //$NON-NLS-1$
        }
    } else if (e.widget == removeAllBtn_sysIncGrp) {
        list_systemInc.removeAll();
        updateButtons();
    } else if (e.widget == browseBld) {
        FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell());
        dialog.setFilterExtensions(new String[] { "*.inf" });
        String fileName = null;

        if ((fileName = dialog.open()) != null) {
            bldInfPath.add(fileName, 0);
            bldInfPath.select(0);

            Event event = new Event();
            event.type = SWT.Selection;
            bldInfPath.notifyListeners(SWT.Selection, event);
        }
    } else if (e.widget == infCheck) {
        projExists = false;
        if (infCheck.getSelection()) {
            bldInfPath.setEnabled(true);
            browseBld.setEnabled(true);

            if (bldInfPath.getText().length() > 0) {
                userFiles = new ArrayList<File>();
                systemFiles = new ArrayList<File>();

                bldPath = bldInfPath.getText();
                selectedSdk = sdkItems[sdkCmb.getSelectionIndex()];

                File bldFile = new File(bldPath);
                File Project = bldFile.getParentFile().getParentFile();

                if (!bldFile.exists()) {
                    MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                            Messages.getString("HeaderFilesPage.CompatibilityAnalyser"),
                            "Given Bld.inf does not exist. Please provide a valid path");
                    return;
                }

                projName = Project.getName();
                projLocation = Project.getAbsolutePath();

                IRunnableWithProgress runnable = new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor) {
                        try {
                            isCancelled = false;
                            selectedProj = ResourcesPlugin.getWorkspace().getRoot()
                                    .getProject("CompatibilityAnalyser_" + projName);
                            if (selectedProj.exists()) {
                                projExists = true;
                            } else {
                                for (IProject wsProj : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
                                    projLocation = FileMethods.convertForwardToBackwardSlashes(projLocation);
                                    if (FileMethods
                                            .convertForwardToBackwardSlashes(wsProj.getLocation().toString())
                                            .equals(projLocation)) {
                                        projExists = true;
                                        selectedProj = wsProj;
                                        break;
                                    }
                                }
                            }

                            java.util.List<ISymbianBuildContext> buildList = selectedSdk
                                    .getFilteredBuildConfigurations();
                            java.util.List<String> infsList = new ArrayList<String>();

                            if (!projExists) {
                                monitor.beginTask("Getting Project Info", 10);
                                selectedProj = ProjectCorePlugin
                                        .createProject("CompatibilityAnalyser_" + projName, projLocation);
                                projDeletionReq = true;
                                monitor.worked(2);

                                if (monitor.isCanceled()) {
                                    isCancelled = true;
                                    if (selectedProj != null && selectedProj.exists()) {
                                        try {
                                            selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                        } catch (Exception e1) {
                                            e1.printStackTrace();
                                        }
                                    }
                                    monitor.done();
                                    projDeletionReq = false;
                                    return;
                                }

                                ProjectCorePlugin.postProjectCreatedActions(selectedProj, "group/bld.inf",
                                        buildList, infsList, null, null, monitor);
                                monitor.worked(5);

                                if (monitor.isCanceled()) {
                                    isCancelled = true;
                                    if (selectedProj != null && selectedProj.exists()) {
                                        try {
                                            selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                        } catch (Exception e1) {
                                            e1.printStackTrace();
                                        }
                                    }
                                    monitor.done();
                                    projDeletionReq = false;
                                    return;
                                }
                                ICarbideProjectInfo projInfo = CarbideBuilderPlugin.getBuildManager()
                                        .getProjectInfo(selectedProj);

                                if (projInfo != null) {

                                    EpocEngineHelper.getProjectIncludePaths(projInfo,
                                            projInfo.getDefaultConfiguration(), userFiles, systemFiles);
                                    getExportPathsAndFiles(projInfo, userFiles);
                                    monitor.worked(7);
                                    srcRoots = CompatibilityAnalyserEngine.getIncludesFromSrcFiles(selectedProj)
                                            .toArray(new String[0]);

                                    monitor.worked(9);
                                    if (monitor.isCanceled())
                                        isCancelled = true;
                                }
                                monitor.done();
                            } else {
                                monitor.beginTask("Reading Project Info..", 10);
                                selectedProj.open(null);
                                monitor.worked(2);

                                if (monitor.isCanceled()) {
                                    isCancelled = true;
                                    monitor.done();
                                    return;
                                }
                                ICarbideProjectInfo projInfo = CarbideBuilderPlugin.getBuildManager()
                                        .getProjectInfo(selectedProj);

                                ICarbideBuildManager manager = CarbideBuilderPlugin.getBuildManager();
                                ICarbideProjectModifier modifier = manager.getProjectModifier(selectedProj);

                                ICarbideBuildConfiguration origConf = projInfo.getDefaultConfiguration();

                                ICarbideBuildConfiguration configTobeSet = null;
                                java.util.List<ISymbianBuildContext> all = selectedSdk
                                        .getFilteredBuildConfigurations();
                                configTobeSet = modifier.createNewConfiguration(all.get(0), true);
                                configTobeSet.saveConfiguration(false);
                                modifier.setDefaultConfiguration(configTobeSet);
                                modifier.saveChanges();

                                if (monitor.isCanceled()) {
                                    isCancelled = true;
                                    modifier.setDefaultConfiguration(origConf);
                                    modifier.saveChanges();

                                    monitor.done();
                                    return;
                                }
                                monitor.worked(5);

                                if (projInfo != null) {

                                    EpocEngineHelper.getProjectIncludePaths(projInfo,
                                            projInfo.getDefaultConfiguration(), userFiles, systemFiles);
                                    getExportPathsAndFiles(projInfo, userFiles);
                                    srcRoots = CompatibilityAnalyserEngine.getIncludesFromSrcFiles(selectedProj)
                                            .toArray(new String[0]);
                                }

                                monitor.worked(8);
                                modifier.setDefaultConfiguration(origConf);
                                modifier.saveChanges();

                                if (monitor.isCanceled())
                                    isCancelled = true;

                                monitor.worked(10);

                                monitor.done();
                            }

                        } catch (CoreException ex) {
                            ex.printStackTrace();
                            try {
                                if (selectedProj != null && selectedProj.exists() && projDeletionReq) {
                                    selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                    projDeletionReq = false;
                                }
                                return;
                            } catch (Exception e1) {
                                e1.printStackTrace();
                            }
                        }
                    }

                };

                try {
                    new ProgressMonitorDialog(this.shell.getShell()).run(true, true, runnable);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }

                if (isCancelled)
                    return;

                if (srcRoots != null && srcRoots.length > 0) {
                    forced_hdrs_list.setItems(srcRoots);
                }

                if (systemFiles != null && systemFiles.size() > 0) {
                    String[] sysIncludes = new String[systemFiles.size()];

                    for (int i = 0; i < systemFiles.size(); i++)
                        sysIncludes[i] = systemFiles.get(i).toString();

                    list_systemInc.setItems(sysIncludes);
                    list_systemInc.select(0);
                    removeBtn_sysIncGrp.setEnabled(true);
                    removeAllBtn_sysIncGrp.setEnabled(true);
                }
                if (userFiles != null && userFiles.size() > 0) {
                    ArrayList<String> userIncludes = new ArrayList<String>();

                    for (int i = 0; i < userFiles.size(); i++) {
                        if (userFiles.get(i).exists())
                            userIncludes.add(
                                    FileMethods.convertForwardToBackwardSlashes(userFiles.get(i).toString()));
                    }

                    radio_default_Hdr.setSelection(false);
                    radio_Hdr_dir.setSelection(true);
                    hdr_dir_list.setItems(userIncludes.toArray(new String[0]));
                    hdr_dir_list.select(0);
                    Event selEvent = new Event();
                    selEvent.type = SWT.Selection;
                    radio_Hdr_dir.notifyListeners(SWT.Selection, selEvent);
                }
            }
        }

        else {
            bldInfPath.setEnabled(false);
            browseBld.setEnabled(false);

            if (bldInfPath.getText().length() > 0) {
                Event modEvent = new Event();
                modEvent.type = SWT.Selection;
                radio_default_Hdr.setSelection(true);
                radio_Hdr_dir.setSelection(false);
                list_systemInc.removeAll();
                hdr_dir_list.removeAll();
                forced_hdrs_list.removeAll();

                radio_default_Hdr.notifyListeners(SWT.Selection, modEvent);
            }
        }
    } else if (e.widget == bldInfPath) {
        radio_default_Hdr.setSelection(true);
        radio_Hdr_dir.setSelection(false);
        list_systemInc.removeAll();
        forced_hdrs_list.removeAll();

        Event modEvent = new Event();
        modEvent.type = SWT.Selection;
        radio_default_Hdr.notifyListeners(SWT.Selection, modEvent);

        bldPath = bldInfPath.getText();
        selectedSdk = sdkItems[sdkCmb.getSelectionIndex()];
        projExists = false;
        if (bldPath.length() > 0 && infCheck.getSelection()) {
            userFiles = new ArrayList<File>();
            systemFiles = new ArrayList<File>();

            File bldFile = new File(bldPath);
            File Project = bldFile.getParentFile().getParentFile();

            if (!bldFile.exists()) {
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                        Messages.getString("HeaderFilesPage.CompatibilityAnalyser"),
                        "Given Bld.inf does not exist. Please provide a valid path");
                return;
            }
            if (!bldFile.getName().equalsIgnoreCase("bld.inf")) {
                return;
            }
            projName = Project.getName();
            projLocation = Project.getAbsolutePath();

            if (selectedProj != null && selectedProj.exists() && projDeletionReq) {
                try {
                    selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }

                projDeletionReq = false;
            }

            IRunnableWithProgress runP = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {

                        isCancelled = false;

                        selectedProj = ResourcesPlugin.getWorkspace().getRoot()
                                .getProject("CompatibilityAnalyser_" + projName);

                        if (selectedProj.exists()) {
                            projExists = true;
                        } else {

                            for (IProject wsProj : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
                                if (FileMethods.convertForwardToBackwardSlashes(wsProj.getLocation().toString())
                                        .equals(FileMethods.convertForwardToBackwardSlashes(projLocation))) {
                                    projExists = true;
                                    selectedProj = wsProj;
                                    break;
                                }
                            }
                        }

                        java.util.List<ISymbianBuildContext> buildList = selectedSdk
                                .getFilteredBuildConfigurations();
                        java.util.List<String> infsList = new ArrayList<String>();

                        if (!projExists) {
                            monitor.beginTask("Getting Project Info...", 10);
                            selectedProj = ProjectCorePlugin.createProject("CompatibilityAnalyser_" + projName,
                                    projLocation);
                            projDeletionReq = true;
                            monitor.worked(2);

                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                if (selectedProj != null && selectedProj.exists()) {
                                    try {
                                        selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                    } catch (Exception e1) {
                                        e1.printStackTrace();
                                    }
                                }
                                monitor.done();
                                projDeletionReq = false;
                                return;
                            }

                            ProjectCorePlugin.postProjectCreatedActions(selectedProj, "group/bld.inf",
                                    buildList, infsList, null, null, monitor);

                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                if (selectedProj != null && selectedProj.exists()) {
                                    try {
                                        selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                    } catch (Exception e1) {
                                        e1.printStackTrace();
                                    }
                                }
                                monitor.done();
                                projDeletionReq = false;

                                return;
                            }
                            monitor.worked(5);
                            ICarbideProjectInfo projInfo = CarbideBuilderPlugin.getBuildManager()
                                    .getProjectInfo(selectedProj);

                            if (projInfo != null) {

                                EpocEngineHelper.getProjectIncludePaths(projInfo,
                                        projInfo.getDefaultConfiguration(), userFiles, systemFiles);
                                getExportPathsAndFiles(projInfo, userFiles);
                                monitor.worked(7);

                                srcRoots = CompatibilityAnalyserEngine.getIncludesFromSrcFiles(selectedProj)
                                        .toArray(new String[0]);

                                monitor.worked(9);
                                if (monitor.isCanceled())
                                    isCancelled = true;
                            }
                            monitor.done();
                        } else {
                            monitor.beginTask("Reading Project Info..", 10);
                            selectedProj.open(null);
                            monitor.worked(2);

                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                monitor.done();
                                return;
                            }
                            ICarbideProjectInfo projInfo = CarbideBuilderPlugin.getBuildManager()
                                    .getProjectInfo(selectedProj);

                            ICarbideBuildManager manager = CarbideBuilderPlugin.getBuildManager();
                            ICarbideProjectModifier modifier = manager.getProjectModifier(selectedProj);

                            ICarbideBuildConfiguration origConf = projInfo.getDefaultConfiguration();

                            ICarbideBuildConfiguration configTobeSet = null;

                            configTobeSet = modifier.createNewConfiguration(buildList.get(0), true);
                            configTobeSet.saveConfiguration(false);
                            modifier.setDefaultConfiguration(configTobeSet);
                            modifier.saveChanges();

                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                monitor.done();
                                modifier.setDefaultConfiguration(origConf);
                                modifier.saveChanges();

                                return;
                            }
                            monitor.worked(5);
                            if (projInfo != null) {
                                EpocEngineHelper.getProjectIncludePaths(projInfo,
                                        projInfo.getDefaultConfiguration(), userFiles, systemFiles);
                                getExportPathsAndFiles(projInfo, userFiles);
                                srcRoots = CompatibilityAnalyserEngine.getIncludesFromSrcFiles(selectedProj)
                                        .toArray(new String[0]);
                            }
                            if (monitor.isCanceled()) {
                                isCancelled = true;
                                monitor.done();
                            }
                            monitor.worked(8);
                            modifier.setDefaultConfiguration(origConf);
                            modifier.saveChanges();
                            monitor.worked(10);
                            monitor.done();
                        }

                    } catch (CoreException ex) {
                        ex.printStackTrace();
                        try {
                            if (selectedProj != null && selectedProj.exists() && projDeletionReq) {
                                selectedProj.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, null);
                                projDeletionReq = false;
                            }
                            return;
                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                }

            };
            try {
                new ProgressMonitorDialog(this.shell.getShell()).run(true, true, runP);
            } catch (Exception ex) {
                ex.printStackTrace();
            }

            if (isCancelled)
                return;

            if (srcRoots != null && srcRoots.length > 0) {
                Event eve = new Event();
                eve.type = SWT.Selection;
                forced_hdrs_list.setItems(srcRoots);
            }
            if (userFiles != null && userFiles.size() > 0) {
                ArrayList<String> userIncludes = new ArrayList<String>();

                for (int i = 0; i < userFiles.size(); i++) {
                    if (userFiles.get(i).exists())
                        userIncludes
                                .add(FileMethods.convertForwardToBackwardSlashes(userFiles.get(i).toString()));
                }

                radio_default_Hdr.setSelection(false);
                radio_Hdr_dir.setSelection(true);
                hdr_dir_list.setItems(userIncludes.toArray(new String[0]));
                hdr_dir_list.select(0);
                Event selEvent = new Event();
                selEvent.type = SWT.Selection;
                radio_Hdr_dir.notifyListeners(SWT.Selection, selEvent);
            }

            if (systemFiles != null && systemFiles.size() > 0) {
                String[] sysIncludes = new String[systemFiles.size()];

                for (int i = 0; i < systemFiles.size(); i++)
                    sysIncludes[i] = systemFiles.get(i).toString();

                list_systemInc.setItems(sysIncludes);
                list_systemInc.select(0);
                removeBtn_sysIncGrp.setEnabled(true);
                removeAllBtn_sysIncGrp.setEnabled(true);
            }
        }
    } else if (e.widget == forced_addBtn) {
        displayFiles = new ArrayList<String>();
        numOfFiles = new ArrayList<String>();
        children = new ArrayList<String>();
        subChildren = new ArrayList<String>();
        isMonitorCancelled = false;

        if (list_systemInc.getItemCount() > 0) {
            ArrayList<String> paths = new ArrayList<String>(Arrays.asList(list_systemInc.getItems()));
            paths.add(FileMethods.appendPathSeparator(sdkrootLbl.getText()) + "epoc32" + File.separator
                    + "include" + File.separator);
            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), forced_hdrs_list, this,
                    "", true);
            allSysIncHdrPaths = paths.toArray(new String[paths.size()]);
            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        int i = 1;
                        for (String path : allSysIncHdrPaths) {
                            absolutePath = FileMethods.convertForwardToBackwardSlashes(path);
                            monitor.beginTask("Getting files from " + absolutePath, allSysIncHdrPaths.length);
                            getFiles(absolutePath, monitor);
                            getFilesFromSubDirs(absolutePath, monitor);
                            monitor.worked(i++);
                        }
                        monitor.done();

                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };

            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }
        } else {
            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), forced_hdrs_list, this,
                    FileMethods.appendPathSeparator(sdkrootLbl.getText()) + "epoc32" + File.separator
                            + "include" + File.separator,
                    true);
            absolutePath = FileMethods.appendPathSeparator(sdkrootLbl.getText()) + "epoc32" + File.separator
                    + "include" + File.separator;
            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        addFiles_monitor = monitor;
                        monitor.beginTask("Getting files from " + absolutePath, 10);
                        getFiles(absolutePath, monitor);
                        addFiles_monitor.worked(5);
                        getFilesFromSubDirs(absolutePath, monitor);
                        monitor.done();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };

            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }
        }

        if (!isMonitorCancelled) {
            if (numOfFiles.size() != forced_hdrs_list.getItemCount())
                for (String name : numOfFiles)
                    if (!isPreviouslySelected(name))
                        displayFiles.add(name);

            if (displayFiles.size() != 0) {
                Collections.sort(displayFiles);
                addDialog.children = children;
                addDialog.subChildren = subChildren;
                addDialog.open();
                addDialog.filesList.setItems(displayFiles.toArray(new String[displayFiles.size()]));
                addDialog.filesList.select(0);
            }
        }

        if (isMonitorCancelled) {

        } else if (displayFiles.size() == 0 && numOfFiles.size() != 0) {

            Runnable showMessageRunnable = new Runnable() {
                public void run() {
                    MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                            Messages.getString("HeaderFilesPage.CompatibilityAnalyser"), //$NON-NLS-1$
                            Messages.getString("HeaderFilesPage.hdrsAlreadyExists")); //$NON-NLS-1$
                }
            };
            Display.getDefault().asyncExec(showMessageRunnable);

        } else if (numOfFiles.size() == 0) {
            Runnable showMessageRunnable = new Runnable() {
                public void run() {
                    MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                            Messages.getString("HeaderFilesPage.CompatibilityAnalyser"), //$NON-NLS-1$
                            Messages.getString("HeaderFilesPage.NoHdrsExists")); //$NON-NLS-1$
                }
            };
            Display.getDefault().asyncExec(showMessageRunnable);
        } else {
            addDialog.fileNamesList = addDialog.filesList.getItems();
        }
    } else if (e.widget == forced_removeBtn) {
        forced_hdrs_list.remove(forced_hdrs_list.getSelectionIndices());
        forced_hdrs_list.select(0);

        forced_removeBtn.setEnabled(forced_hdrs_list.getItemCount() > 0);
        forced_removeAllBtn.setEnabled(forced_hdrs_list.getItemCount() > 0);
    } else if (e.widget == forced_removeAllBtn) {
        forced_hdrs_list.removeAll();
        forced_removeBtn.setEnabled(false);
        forced_removeAllBtn.setEnabled(false);
    } else if (e.widget == show_btn) {
        GridData data = (GridData) adv_options_comp.getLayoutData();
        data.exclude = false;
        adv_options_comp.setVisible(true);

        ((StackLayout) show_hide_button_comp.getLayout()).topControl = hide_btn;
        show_hide_button_comp.layout();
    } else if (e.widget == hide_btn) {
        GridData data = (GridData) adv_options_comp.getLayoutData();
        data.exclude = true;
        adv_options_comp.setVisible(false);

        ((StackLayout) show_hide_button_comp.getLayout()).topControl = show_btn;
        show_hide_button_comp.layout();
    }

    if (!shell.isDisposed()) {
        hdrGrp.layout();
        shell.layout();
    }
}

From source file:com.nokia.s60tools.memspy.ui.UiUtils.java

License:Open Source License

/**
 * Advises used to install MemSpy launcher component and provides necessary action alternatives.
 * @param errorMessage error message//from  www  .  ja  v  a  2  s. co  m
 */
private static void adviceUserToInstallLauncherComponent(final String errorMessage) {

    MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
            IMemSpyTraceListener.ERROR_MEMSPY, null, errorMessage, MessageDialog.ERROR,
            new String[] { "Install RnD-signed MemSpy Launcher", "Open sis-file's directory in Explorer",
                    "Don't install" },
            1);
    dialog.open();

    String launcherFolder = MemSpyPlugin.getDefault().getMemspyLauncherBinDir();
    String launcherLocation = launcherFolder + File.separatorChar
            + MEM_SPY_LAUNCHER_S60_50_RN_D_SIGNED_SIS_FILE_NAME;

    // if user wants to install launcher:
    if (dialog.getReturnCode() == 0) {
        // find program for xls-filetype
        Program p = Program.findProgram(".sis");
        // if found, launch it.
        if (p != null) {
            // Check that found program was Nokia PC Suite.
            p.execute(launcherLocation);
        } else {
            Status status = new Status(IStatus.ERROR, MemSpyPlugin.PLUGIN_ID, 0,
                    "Unable to locate PC suite or other suitable software for installing .sis -file from computer. You can try installing MemSpy launcher manually from:\n"
                            + launcherLocation,
                    null);
            ErrorDialog.openError(Display.getCurrent().getActiveShell(), "MemSpy Error", null, status);
        }

    }

    // Open directory in explorer
    else if (dialog.getReturnCode() == 1) {
        try {
            String directory = Platform.getConfigurationLocation().getURL().getFile();
            directory = directory.substring(1);
            Runtime.getRuntime().exec("explorer " + launcherFolder);
        } catch (IOException e) {
            Status status = new Status(IStatus.ERROR, MemSpyPlugin.PLUGIN_ID, 0, "Unable to open Explorer",
                    null);
            ErrorDialog.openError(Display.getCurrent().getActiveShell(), IMemSpyTraceListener.ERROR_MEMSPY,
                    null, status);
            e.printStackTrace();
        }
    }

}

From source file:com.nokia.s60tools.stif.scripteditor.editors.ScriptEditor.java

License:Open Source License

/**
 * Reads editor mode from file persistant property
 * @return editor mode //  w w  w  .j a  v a  2  s.  c  o m
 */
private EditorMode queryEditorMode() {
    EditorMode mode = null;
    String dialogTitle = "Choose the proper editor mode";
    String modeQuestion = "Choose the proper editor mode (it will be possible to change the mode later)";
    String scripterButtonText = "test scripter";
    String combinerButtonText = "test combiner";
    MessageDialog modeDialog = new MessageDialog(
            org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dialogTitle, null,
            modeQuestion, 0, new String[] { scripterButtonText, combinerButtonText }, 0);
    int numericChosenMode = modeDialog.open();
    if (numericChosenMode == 0) {
        mode = EditorMode.scripterMode;
    } else {
        mode = EditorMode.combinerMode;
    }

    return mode;
}

From source file:com.nokia.sdt.symbian.ui.appeditor.ApplicationEditor.java

License:Open Source License

/**
 * Because of the app editor's synchronize on save behavior we need to customize
 * the close->ask save changes flow. If the user says "yes" to the built-in "Save changes"
 * query, the editor is definitely going to close. But our "confirm application changes" dialog
 * has a cancel. If they cancel there the changes would be thrown away
 *///from ww w .  j  a v a 2 s.  c  om
public int promptToSaveOnClose() {
    if (!isDirty()) {
        return NO;
    }
    PreflightInfo pi = calcPreflightInfo(true);
    if (pi.changeFlags == 0 || pi.dialogMessage == null) {
        return DEFAULT;
    }

    String title = Messages.getString("ApplicationEditor.saveDialogTitle"); //$NON-NLS-1$
    String labels[];
    if (pi.preSaveOtherEditorsNeeded) {
        labels = new String[] { Messages.getString("ApplicationEditor.saveAllButton"), //$NON-NLS-1$
                Messages.getString("ApplicationEditor.dontSaveButton"), //$NON-NLS-1$
                Messages.getString("ApplicationEditor.cancelButton") }; //$NON-NLS-1$
    } else {
        labels = new String[] { Messages.getString("ApplicationEditor.saveButton"), //$NON-NLS-1$
                Messages.getString("ApplicationEditor.dontSaveButton"), //$NON-NLS-1$
                Messages.getString("ApplicationEditor.cancelButton") }; //$NON-NLS-1$
    }
    MessageDialog dialog = new MessageDialog(getEditorSite().getShell(), title, null, pi.dialogMessage,
            MessageDialog.QUESTION, labels, YES);
    int result = dialog.open();
    if (result == YES) {
        // set after user approves actions, so we don't requery from doSave
        closingEditorPreflightInfo = pi;
    }
    return result;
}

From source file:com.nokia.sdt.uidesigner.events.EventCommands.java

License:Open Source License

public static void navigateToHandlerCode(EventPage page, IEventBinding binding, boolean isNewBinding) {
    IEventDescriptor eventDescriptor = binding.getEventDescriptor();
    IStatus status = eventDescriptor.gotoHandlerCode(binding, isNewBinding);
    if (status != null) {
        if (!isNewBinding) {
            // Hmm, an error.  It could be the data model was not saved.
            // It may just be a problem in the component's sourcegen, hence
            // the fallthrough to the descriptive error later.
            MessageDialog dialog = new MessageDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.getString("EventCommands.Error"), null, //$NON-NLS-1$
                    Messages.getString("EventCommands.NoEventHandlerFound"), //$NON-NLS-1$
                    MessageDialog.QUESTION,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, //$NON-NLS-1$ //$NON-NLS-2$
                    0);/*from  w w  w . j av a  2 s. c  o  m*/
            int result = dialog.open();
            if (result == MessageDialog.OK) {
                if (page.saveDataModel()) {
                    status = eventDescriptor.gotoHandlerCode(binding, isNewBinding);
                }
            }
        }
        if (status != null) {
            Logging.log(UIDesignerPlugin.getDefault(), status);
        }
    }

}

From source file:com.nokia.tools.s60.views.ColorsViewPage.java

License:Open Source License

public void fillTable() {
    for (ColorQuadruple input : inputs) {
        if (!table.isDisposed()) {
            final Composite labelComp = new Composite(table, SWT.NONE);
            GridLayout gl = new GridLayout();
            gl.marginWidth = gl.marginHeight = gl.horizontalSpacing = gl.verticalSpacing = 0;
            labelComp.setLayout(gl);//www.j a v a 2s . c  o  m
            GridData gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.grabExcessHorizontalSpace = true;
            gd.horizontalSpan = 3;
            gd.verticalIndent = 5;
            labelComp.setLayoutData(gd);
            labelComp.setBackground(labelComp.getParent().getBackground());

            final Text label = new Text(labelComp, SWT.NONE);
            label.setEditable(false);
            label.setData(input);
            gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.grabExcessHorizontalSpace = true;
            gd.grabExcessVerticalSpace = true;
            label.setLayoutData(gd);
            label.setFont(ItalicFont);

            label.setText(input.getQuadrupleName());

            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseDown(MouseEvent e) {
                    if (e.button == 1) {
                        label.setFont(null);
                        label.setEditable(true);
                        labelComp.setBackground(ColorConstants.white);
                    }
                }
            });

            label.addMouseTrackListener(new MouseTrackListener() {
                public void mouseEnter(MouseEvent e) {

                }

                public void mouseExit(MouseEvent e) {
                    label.setFont(ItalicFont);
                    label.setEditable(false);
                    // this will call the focus lost event
                    label.setEnabled(false);
                    if (!label.isDisposed()) {
                        label.setEnabled(true);
                        labelComp.setBackground(labelComp.getParent().getBackground());
                    }
                }

                public void mouseHover(MouseEvent e) {

                }
            });

            label.addTraverseListener(new TraverseListener() {
                public void keyTraversed(TraverseEvent e) {
                    if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
                        ColorQuadruple quad = (ColorQuadruple) label.getData();

                        if (e.detail == SWT.TRAVERSE_ESCAPE) {
                            label.setText(quad.getQuadrupleName());
                        } else if (e.detail == SWT.TRAVERSE_RETURN) {
                            //the focus lost will happen
                            // after this
                            // if (!updateName(quad, label.getText())) {
                            // label.setText(quad.getQuadrupleName());
                            // }
                        }

                        label.setFont(ItalicFont);
                        label.setEditable(false);
                        // this will call the focus lost event
                        label.setEnabled(false);
                        if (!label.isDisposed()) {
                            label.setEnabled(true);
                            labelComp.setBackground(labelComp.getParent().getBackground());
                        }
                    }
                }
            });

            label.addFocusListener(new FocusAdapter() {
                @Override
                public void focusLost(FocusEvent e) {
                    label.setFont(ItalicFont);
                    label.setEditable(false);
                    label.setEnabled(false);
                    label.setEnabled(true);
                    labelComp.setBackground(labelComp.getParent().getBackground());
                    ColorQuadruple quad = (ColorQuadruple) label.getData();
                    if (!updateName(quad, label.getText())) {
                        label.setText(quad.getQuadrupleName());
                    }
                }

                @Override
                public void focusGained(FocusEvent e) {
                    label.setFont(null);
                    label.setEditable(true);
                    labelComp.setBackground(ColorConstants.white);
                }
            });

            final Canvas quadrupleComposite = new Canvas(table, SWT.BORDER);
            quadrupleComposite.addPaintListener(new PaintListener() {
                public void paintControl(PaintEvent e) {
                    GC gc = e.gc;
                    gc.setBackground(ColorConstants.white);
                    // gc.setBackgroundPattern(BG_PATTERN);
                    gc.fillRectangle(0, 0, quadrupleComposite.getSize().x, quadrupleComposite.getSize().y);
                }
            });
            gl = new GridLayout(4, false);
            gl.marginWidth = 2;
            gl.marginHeight = gl.horizontalSpacing = gl.verticalSpacing = 0;
            quadrupleComposite.setLayout(gl);
            gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.heightHint = rowHeight;
            gd.verticalAlignment = SWT.CENTER;
            quadrupleComposite.setLayoutData(gd);

            Canvas q1 = new Canvas(quadrupleComposite, SWT.NONE);
            q1.setData(input);
            gd = new GridData();
            gd.grabExcessVerticalSpace = true;
            gd.widthHint = QuadrupleColumnWidth;
            gd.heightHint = rowHeight;
            gd.verticalAlignment = SWT.CENTER;
            q1.setLayoutData(gd);
            q1.setBackground(q1.getParent().getBackground());
            addPaintListener(0, q1);
            addDragSource(0, q1);
            addQuadrupleMouseListener(0, q1);
            createTooltip(0, q1);

            Canvas q2 = new Canvas(quadrupleComposite, SWT.NONE);
            q2.setData(input);
            gd = new GridData();
            gd.grabExcessVerticalSpace = true;
            gd.widthHint = QuadrupleColumnWidth;
            gd.heightHint = rowHeight;
            gd.verticalAlignment = SWT.CENTER;
            gd.horizontalIndent = 6;
            q2.setLayoutData(gd);
            q2.setBackground(q2.getParent().getBackground());
            addPaintListener(1, q2);
            addDragSource(1, q2);
            addQuadrupleMouseListener(1, q2);
            createTooltip(1, q2);

            Canvas q3 = new Canvas(quadrupleComposite, SWT.NONE);
            q3.setData(input);
            gd = new GridData();
            gd.grabExcessVerticalSpace = true;
            gd.widthHint = QuadrupleColumnWidth;
            gd.heightHint = rowHeight;
            gd.verticalAlignment = SWT.CENTER;
            q3.setLayoutData(gd);
            q3.setBackground(q3.getParent().getBackground());
            addPaintListener(2, q3);
            addDragSource(2, q3);
            addQuadrupleMouseListener(2, q3);
            createTooltip(2, q3);

            Canvas q4 = new Canvas(quadrupleComposite, SWT.NONE);
            q4.setData(input);
            gd = new GridData();
            gd.grabExcessVerticalSpace = true;
            gd.widthHint = QuadrupleColumnWidth;
            gd.heightHint = rowHeight;
            gd.verticalAlignment = SWT.CENTER;
            q4.setLayoutData(gd);
            q4.setBackground(q4.getParent().getBackground());
            addPaintListener(3, q4);
            addDragSource(3, q4);
            addQuadrupleMouseListener(3, q4);
            createTooltip(3, q4);

            final Button b1 = new Button(table, SWT.FLAT);
            b1.setData(input);
            gd = new GridData();
            gd.grabExcessHorizontalSpace = false;
            gd.heightHint = 20;
            gd.widthHint = 20;
            gd.verticalAlignment = SWT.CENTER;
            b1.setLayoutData(gd);
            b1.setBackground(b1.getParent().getBackground());
            b1.setImage(CopyGroupImage);
            b1.setToolTipText("Copy Color Group as a new Group");

            b1.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    CommandStack stck = (CommandStack) sourceEditor.getAdapter(CommandStack.class);

                    Command cmd = new Command() {
                        @Override
                        public boolean canExecute() {
                            return true;
                        }

                        @Override
                        public boolean canUndo() {
                            return false;
                        }

                        @Override
                        public void execute() {
                            ColorQuadruple quad = (ColorQuadruple) b1.getData();
                            ColorQuadruple newQuad = new ColorQuadruple("copy of " + quad.getQuadrupleName());
                            ColorGroups grps = getColorGroups();

                            int idx = 1;
                            while (grps.getGroupByName(newQuad.getQuadrupleName()) != null) {
                                idx++;
                                newQuad = new ColorQuadruple(
                                        "copy (" + idx + ") of " + quad.getQuadrupleName());
                            }

                            for (int i = 0; i < quad.getRgbList().size(); i++) {
                                RGB rgb = quad.getRgbList().get(i);
                                // (add group notifies this observer about
                                // adding
                                // group)
                                if (i == 0) {
                                    if (grps.addGroup(newQuad.getQuadrupleName(), rgb) == true) {
                                        // newQuad.addRGB(rgb, false);
                                        // inputs.add(newQuad);
                                    }
                                } else {
                                    String newName = newQuad.getQuadrupleName() + " tone" + i;
                                    if (grps.addGroup(newName, rgb) == true) {
                                        // newQuad.addRGB(rgb, false);
                                        ColorGroup added = grps.getGroupByName(newName);
                                        added.setParentGroupName(newQuad.getQuadrupleName());
                                    }
                                }
                            }
                        }
                    };

                    if (stck != null) {
                        stck.execute(cmd);
                    } else {
                        cmd.execute();
                    }
                }
            });

            final Button b2 = new Button(table, SWT.FLAT);
            b2.setData(input);
            gd = new GridData();
            gd.grabExcessHorizontalSpace = false;
            gd.heightHint = 20;
            gd.widthHint = 20;
            gd.verticalAlignment = SWT.CENTER;
            b2.setLayoutData(gd);
            b2.setBackground(b2.getParent().getBackground());
            b2.setImage(DeleteGroupImage);
            b2.setToolTipText("Delete Color Group");

            b2.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    CommandStack stck = (CommandStack) sourceEditor.getAdapter(CommandStack.class);

                    Command cmd = new Command() {
                        @Override
                        public boolean canExecute() {
                            return true;
                        }

                        @Override
                        public boolean canUndo() {
                            return false;
                        }

                        @Override
                        public void execute() {
                            ColorQuadruple quad = (ColorQuadruple) b2.getData();
                            IBrandingManager branding = BrandingExtensionManager.getBrandingManager();
                            Image image = null;
                            if (branding != null) {
                                image = branding.getIconImageDescriptor().createImage();
                            }
                            MessageDialog dialog = new MessageDialog(
                                    PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                                    ViewMessages.RefColors_Delete_MsgBox_Title, image,
                                    MessageFormat.format(ViewMessages.RefColors_Delete_MsgBox_Message,
                                            new Object[] { quad.getQuadrupleName() }),
                                    3, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
                                    1);
                            dialog.create();
                            image.dispose();
                            if (dialog.open() == 0) {
                                inputs.remove(quad);
                                ColorGroups grps = getColorGroups();
                                grps.removeGroup(quad.getQuadrupleName());
                                for (int i = 1; i <= 3; i++) {
                                    // (remove group notifies this observer
                                    // about group
                                    // removal
                                    grps.removeGroup(quad.getQuadrupleName() + " tone" + i);
                                }

                            }
                        }
                    };

                    if (stck != null) {
                        stck.execute(cmd);
                    } else {
                        cmd.execute();
                    }
                }
            });
        }
    }
}

From source file:com.nokia.tools.screen.ui.utils.FileChangeWatchThread.java

License:Open Source License

public static void displayThirdPartyEditorMisssingErrorMessageBox() {
    IBrandingManager branding = BrandingExtensionManager.getBrandingManager();
    Image image = null;//from w ww  .j  a v a 2 s  . c o m
    if (branding != null) {
        image = branding.getIconImageDescriptor().createImage();
    }
    MessageDialog dialog = new MessageDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
            Messages.FileChangeWatchThread_editorSettingsError, image,
            Messages.FileChangeWatchThread_editorError, 1,
            new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
    dialog.open();
    if (image != null) {
        image.dispose();
    }
}