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

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

Introduction

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

Prototype

int WARNING

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

Click Source Link

Document

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

Usage

From source file:com.arc.cdt.debug.seecode.ui.UISeeCodePlugin.java

License:Open Source License

private void checkLicensingAlert(final int daysRemaining) {
    final int alertDays = SeeCodePlugin.getDefault().getPreferences().getInt(
            ISeeCodeConstants.PREF_LICENSE_EXPIRATION_DAYS, ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS);
    if (daysRemaining >= 0) {
        boolean alert = SeeCodePlugin.getDefault().getPreferences()
                .getBoolean(ISeeCodeConstants.PREF_LICENSE_EXPIRATION_ALERT, true);
        if (alertDays >= daysRemaining) {
            if (alert) {
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override/* w w  w  .  j a va 2  s  .c o m*/
                    public void run() {
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        String s;
                        if (daysRemaining == 0)
                            s = "after today";
                        else if (daysRemaining == 1)
                            s = "after tomorrow";
                        else
                            s = "in " + daysRemaining + " days";
                        MessageDialog dialog = new MessageDialog(shell, "License Expiration Alert", null, // accept
                                "Debugger license will expire " + s, MessageDialog.WARNING,
                                new String[] { IDialogConstants.OK_LABEL }, 0) {

                            @Override
                            protected Control createCustomArea(Composite parent) {
                                if (daysRemaining > 0 && daysRemaining <= 2) {
                                    Label label = new Label(parent, SWT.RIGHT);
                                    GridData data = new GridData();
                                    data.horizontalAlignment = GridData.END;
                                    data.grabExcessHorizontalSpace = true;
                                    label.setLayoutData(data);
                                    label.setText("You will be reminded again tomorrow.");
                                    setAlertDays(daysRemaining - 1);
                                    return label;
                                }
                                if (daysRemaining > 0) {
                                    Composite container = new Composite(parent, 0);
                                    GridData data = new GridData();
                                    data.horizontalAlignment = GridData.END;
                                    data.grabExcessHorizontalSpace = true;
                                    container.setLayoutData(data);
                                    container.setLayout(new GridLayout(3, false));
                                    Label label1 = new Label(container, SWT.LEFT);
                                    label1.setText("Remind me again when ");
                                    final Combo combo = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
                                    Label label2 = new Label(container, SWT.LEFT);
                                    label2.setText(" days remain.");
                                    label2.setLayoutData(data);
                                    for (int i = Math.min(15, daysRemaining - 1); i >= 0; i--) {
                                        combo.add("" + i);
                                    }
                                    combo.select(0);
                                    setAlertDays(Integer.parseInt(combo.getItem(0)));
                                    combo.addSelectionListener(new SelectionListener() {

                                        @Override
                                        public void widgetDefaultSelected(SelectionEvent e) {
                                        }

                                        @Override
                                        public void widgetSelected(SelectionEvent e) {
                                            setAlertDays(Integer.parseInt(combo.getText()));
                                        }
                                    });
                                    return container;
                                }
                                return null;
                            }
                        };
                        if (dialog.open() == Window.OK) {
                            SeeCodePlugin.getDefault().getPreferences()
                                    .putInt(ISeeCodeConstants.PREF_LICENSE_EXPIRATION_DAYS, mAlertDays);
                        }
                    }
                });

            }
        } else if (daysRemaining > ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS
                && alertDays != ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS) {
            // License has been renewed. Reset things to default.
            restoreDefaultAlertDays();
        }
    } else if (alertDays != ISeeCodeConstants.DEF_PREF_LICENSE_EXPIRATION_DAYS) {
        // Evidently a permanent license; make sure we reset alert if he previously
        // had an expired one.
        restoreDefaultAlertDays();
    }
}

From source file:com.atolcd.pentaho.di.ui.trans.steps.gisgroupby.GisGroupByDialog.java

License:Open Source License

private void ok() {
    if (Const.isEmpty(wStepname.getText())) {
        return;/*from  w  ww. jav  a2s  .  co m*/
    }

    int sizegroup = wGroup.nrNonEmpty();
    int nrfields = wAgg.nrNonEmpty();
    input.setPrefix(wPrefix.getText());
    input.setDirectory(wSortDir.getText());

    input.setLineNrInGroupField(wLineNrField.getText());
    input.setAlwaysGivingBackOneRow(wAlwaysAddResult.getSelection());

    input.allocate(sizegroup, nrfields);

    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < sizegroup; i++) {
        TableItem item = wGroup.getNonEmpty(i);
        input.getGroupField()[i] = item.getText(1);
    }

    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < nrfields; i++) {
        TableItem item = wAgg.getNonEmpty(i);
        input.getAggregateField()[i] = item.getText(1);
        input.getSubjectField()[i] = item.getText(2);
        input.getAggregateType()[i] = GisGroupByMeta.getType(item.getText(3));
        input.getValueField()[i] = item.getText(4);
    }

    stepname = wStepname.getText();

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

    dispose();
}

From source file:com.bdaum.zoom.operations.internal.MigrateOperation.java

License:Open Source License

@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    List<URI> failedWatchedFolders = new ArrayList<URI>();
    List<URI> watchedFoldersWithFilters = new ArrayList<URI>();
    init(monitor, 1337000);//from   ww w  . jav a2 s.c  o  m
    monitor.subTask(Messages.getString("MigrateOperation.migrating")); //$NON-NLS-1$
    try {
        final Meta oldMeta = dbManager.getMeta(true);
        Meta newMeta = newDbManager.getMeta(true);
        newMeta.setPlatform("$migrated$"); //$NON-NLS-1$
        List<Object> toBeStored = cloneMeta(newDbManager, oldMeta, newMeta, oldMeta.getDescription());
        newMeta.setKeywords(oldMeta.getKeywords());
        Utilities.ensureCatConsistency(oldMeta.getCategory());
        newMeta.setCategory(oldMeta.getCategory());
        newMeta.setCleaned(false);
        newMeta.setCreationDate(oldMeta.getCreationDate());
        newMeta.setRelevantLireVersion(oldMeta.getRelevantLireVersion());
        newMeta.setBackupLocation(migrate(oldMeta.getBackupLocation()));
        if (oldMeta.getColorLabels() != null)
            newMeta.setColorLabels(oldMeta.getColorLabels());
        newMeta.setPersonsToKeywords(oldMeta.getPersonsToKeywords());
        newMeta.setThumbnailResolution(oldMeta.getThumbnailResolution());
        newMeta.setSharpen(oldMeta.getSharpen());
        newMeta.setWebpCompression(oldMeta.getWebpCompression());
        newMeta.setJpegQuality(oldMeta.getJpegQuality());
        newMeta.setThumbnailFromPreview(oldMeta.getThumbnailFromPreview());
        newMeta.setTimeline(oldMeta.getTimeline());
        newMeta.setLocationFolders(oldMeta.getLocationFolders());
        newMeta.setPauseFolderWatch(oldMeta.getPauseFolderWatch());
        newMeta.setReadonly(false);
        newMeta.setAutoWatch(oldMeta.getAutoWatch());
        newMeta.setFolderWatchLatency(oldMeta.getFolderWatchLatency());
        newMeta.setLocale(oldMeta.getLocale());
        newMeta.setCumulateImports(oldMeta.getCumulateImports());
        newMeta.setCbirAlgorithms(CoreActivator.getDefault().getCbirAlgorithms());
        newMeta.setIndexedTextFields(CoreActivator.getDefault().getIndexedTextFields(oldMeta));
        Map<String, LastDeviceImport> lastDeviceImports = oldMeta.getLastDeviceImport();
        if (lastDeviceImports != null)
            toBeStored.addAll(lastDeviceImports.values());
        List<String> watchedFolders = oldMeta.getWatchedFolder();
        if (watchedFolders != null)
            for (String id : watchedFolders) {
                WatchedFolder watchedFolder = dbManager.obtainById(WatchedFolder.class, id);
                String oldUri = watchedFolder.getUri();
                String oldVolume = watchedFolder.getVolume();
                String oldTarget = watchedFolder.getTargetDir();
                String source = migrateUri(oldUri, oldVolume);
                if (source.isEmpty()) {
                    failedWatchedFolders.add(volumeManager.findFile(oldUri, oldVolume));
                    continue;
                }
                if (watchedFolder.getTransfer()) {
                    String target = migrate(oldTarget);
                    if (target.isEmpty()) {
                        failedWatchedFolders.add(volumeManager.findFile(oldUri, oldVolume));
                        continue;
                    }
                    watchedFolder.setTargetDir(target);
                }
                watchedFolder.setUri(toUri(source));
                watchedFolder.setVolume(extractVolume(source));
                String oldFilters = watchedFolder.getFilters();
                if (oldFilters != null && !oldFilters.isEmpty())
                    watchedFoldersWithFilters.add(volumeManager.findFile(oldUri, oldVolume));
                newDbManager.storeAndCommit(watchedFolder);
                newMeta.addWatchedFolder(id);
                watchedFolder.setUri(oldUri);
                watchedFolder.setVolume(oldVolume);
                watchedFolder.setTargetDir(oldTarget);
                if (monitor.isCanceled())
                    return abort();
            }
        if (monitor.isCanceled())
            return abort();
        toBeStored.add(newMeta);
        newDbManager.safeTransaction(null, toBeStored);
        if (monitor.isCanceled())
            return abort();
        monitor.worked(1000);
        monitor.subTask(Messages.getString("MigrateOperation.migrate_groups")); //$NON-NLS-1$
        if (copyObjects(GroupImpl.class, 20000))
            return abort();
        GroupImpl folderGroup = newDbManager.obtainById(GroupImpl.class, Constants.GROUP_ID_FOLDERSTRUCTURE);
        List<Group> oldSubgroup = new ArrayList<Group>(folderGroup.getSubgroup());
        folderGroup.getSubgroup().clear();
        newDbManager.storeAndCommit(folderGroup);
        folderGroup.setSubgroup(oldSubgroup);
        if (copyObjects(ContactImpl.class, 1000))
            return abort();
        if (copyObjects(CreatorsContactImpl.class, 1000))
            return abort();
        if (copyObjects(LocationImpl.class, 1000))
            return abort();
        if (copyObjects(LocationShownImpl.class, 1000))
            return abort();
        if (copyObjects(LocationCreatedImpl.class, 1000))
            return abort();
        if (copyObjects(ArtworkOrObjectImpl.class, 1000))
            return abort();
        if (copyObjects(ArtworkOrObjectShownImpl.class, 1000))
            return abort();
        if (copyObjects(TrackRecordImpl.class, 1000))
            return abort();
        if (copyObjects(RegionImpl.class, 1000))
            return abort();
        if (copyObjects(ComposedToImpl.class, 1000))
            return abort();
        if (copyObjects(DerivedByImpl.class, 1000))
            return abort();
        int i = 0;
        List<Asset> assets = dbManager.obtainObjects(Asset.class);
        int na = assets.size();
        int work = 1000000;
        int incr = na == 0 ? work : work / na;
        for (Asset asset : assets) {
            monitor.subTask(NLS.bind(Messages.getString("MigrateOperation.migrating_image"), ++i, na)); //$NON-NLS-1$
            String oldUri = asset.getUri();
            String oldVolume = asset.getVolume();
            boolean remote = volumeManager.isRemote(asset);
            String migratedPath = migrateUri(oldUri, oldVolume);
            if (remote || !migratedPath.isEmpty()) {
                toBeStored.clear();
                toBeStored.add(asset);
                String assetId = asset.getStringId();
                String oldVoiceFileURI = asset.getVoiceFileURI();
                String oldVoiceVolume = asset.getVoiceVolume();
                String migratedUri = null;
                String migratedVolume = null;
                if (!remote) {
                    migratedUri = toUri(migratedPath);
                    asset.setUri(migratedUri);
                    migratedVolume = extractVolume(migratedPath);
                    asset.setVolume(migratedVolume);
                    String voiceUri = AssetEnsemble.extractVoiceNote(asset);
                    if (voiceUri != null) {
                        String migratedVoicePath = migrateUri(voiceUri, oldVoiceVolume);
                        AssetEnsemble.insertVoiceNote(asset, extractVolume(migratedVoicePath),
                                migratedVoicePath.isEmpty() ? null : toUri(migratedVoicePath));
                    }
                }
                visited.add(assetId);
                List<Ghost_typeImpl> ghosts = dbManager.obtainObjects(Ghost_typeImpl.class,
                        QueryField.NAME.getKey(), asset.getName(), QueryField.EQUALS);
                for (Ghost_typeImpl ghost : ghosts)
                    if (ghost.getUri() != null && ghost.getUri().equals(oldUri) && migratedUri != null) {
                        ghost.setUri(migratedUri);
                        ghost.setVolume(migratedVolume);
                        toBeStored.add(ghost);
                    }
                MediaExtension[] mediaExtensions = asset.getMediaExtension();
                if (mediaExtensions != null)
                    for (MediaExtension mediaExt : mediaExtensions)
                        toBeStored.add(mediaExt);
                newDbManager.safeTransaction(null, toBeStored);
                newDbManager.createFolderHierarchy(asset, winTarget);
                asset.setUri(oldUri);
                asset.setVolume(oldVolume);
                asset.setVoiceFileURI(oldVoiceFileURI);
                asset.setVoiceVolume(oldVoiceVolume);
                for (Object obj : toBeStored)
                    if (obj instanceof Ghost_typeImpl) {
                        ((Ghost_typeImpl) obj).setUri(oldUri);
                        ((Ghost_typeImpl) obj).setVolume(oldVolume);
                    }
            }
            if (monitor.isCanceled())
                return abort();
            monitor.worked(incr);
            work -= incr;
        }
        monitor.worked(work);
        List<SmartCollectionImpl> collections = dbManager.obtainObjects(SmartCollectionImpl.class);
        work = 100000;
        na = collections.size();
        incr = na == 0 ? work : work / na;
        String uriKey = QueryField.URI.getKey() + '=';
        String volumeKey = QueryField.VOLUME.getKey() + '=';
        for (SmartCollectionImpl coll : collections) {
            if (coll.getSmartCollection_subSelection_parent() == null) {
                String id = coll.getStringId();
                if (!id.startsWith(uriKey) && !id.startsWith(volumeKey)) {
                    toBeStored.clear();
                    monitor.subTask(NLS.bind(Messages.getString("MigrateOperation.migrating_collections"), //$NON-NLS-1$
                            coll.getName()));
                    transferSmartCollection(toBeStored, coll, null);
                    newDbManager.safeTransaction(null, toBeStored);
                    if (monitor.isCanceled())
                        return abort();
                }
            }
            monitor.worked(incr);
            work -= incr;
        }
        monitor.worked(work);
        monitor.subTask(Messages.getString("MigrateOperation.migrating_presentations")); //$NON-NLS-1$
        if (copyObjects(SlideShowImpl.class, 5000))
            return abort();
        if (copyObjects(SlideImpl.class, 50000))
            return abort();
        if (copyObjects(ExhibitImpl.class, 50000))
            return abort();
        if (copyObjects(WallImpl.class, 5000))
            return abort();
        List<ExhibitionImpl> exhibitions = dbManager.obtainObjects(ExhibitionImpl.class);
        work = 5000;
        na = exhibitions.size();
        incr = na == 0 ? work : work / na;
        for (ExhibitionImpl exhibition : exhibitions) {
            String oldFolder = exhibition.getOutputFolder();
            if (oldFolder != null) {
                exhibition.setOutputFolder(migrate(oldFolder));
                newDbManager.storeAndCommit(exhibition);
                exhibition.setOutputFolder(oldFolder);
            } else
                newDbManager.storeAndCommit(exhibition);
            if (monitor.isCanceled())
                return abort();
            monitor.worked(incr);
            work -= incr;
        }
        monitor.worked(work);
        if (copyObjects(WebExhibitImpl.class, 50000))
            return abort();
        if (copyObjects(WebParameterImpl.class, 5000))
            return abort();
        if (copyObjects(StoryboardImpl.class, 5000))
            return abort();
        List<WebGalleryImpl> galleries = dbManager.obtainObjects(WebGalleryImpl.class);
        work = 5000;
        na = galleries.size();
        incr = na == 0 ? work : work / na;
        for (WebGalleryImpl exhibition : galleries) {
            String oldFolder = exhibition.getOutputFolder();
            if (oldFolder != null) {
                exhibition.setOutputFolder(migrate(oldFolder));
                newDbManager.storeAndCommit(exhibition);
                exhibition.setOutputFolder(oldFolder);
            } else
                newDbManager.storeAndCommit(exhibition);
            if (monitor.isCanceled())
                return abort();
            monitor.worked(incr);
            work -= incr;
        }
        monitor.subTask(Messages.getString("MigrateOperation.migrating_other_entries")); //$NON-NLS-1$
        monitor.worked(work);
        if (copyObjects(PageLayoutImpl.class, 5000))
            return abort();
        List<BookmarkImpl> bookmarks = dbManager.obtainObjects(BookmarkImpl.class);
        work = 20000;
        na = galleries.size();
        incr = na == 0 ? work : work / na;
        for (BookmarkImpl bookmark : bookmarks) {
            String catFile = bookmark.getCatFile();
            if (catFile == null || new File(catFile).equals(dbManager.getFile())) {
                bookmark.setCatFile(null);
                newDbManager.storeAndCommit(bookmark);
            }
            if (monitor.isCanceled())
                return abort();
            monitor.worked(incr);
            work -= incr;
        }
        monitor.worked(work);
        newDbManager.safeTransaction(null, newMeta);
        if (!failedWatchedFolders.isEmpty() || watchedFoldersWithFilters.isEmpty() || oldMeta.getReadonly()) {
            StringBuilder sb = new StringBuilder();
            sb.append(Messages.getString("MigrateOperation.migration_completed")); //$NON-NLS-1$
            if (!failedWatchedFolders.isEmpty()) {
                sb.append(Messages.getString("MigrateOperation.failed_watched_folders")); //$NON-NLS-1$
                for (URI uri : failedWatchedFolders)
                    sb.append("\n\t").append(new File(uri).getPath()); //$NON-NLS-1$
            }
            if (!watchedFoldersWithFilters.isEmpty()) {
                sb.append(Messages.getString("MigrateOperation.watched_folders_with_filters")); //$NON-NLS-1$
                for (URI uri : watchedFoldersWithFilters)
                    sb.append("\n\t").append(new File(uri).getPath()); //$NON-NLS-1$
            }
            if (oldMeta.getReadonly())
                sb.append(Messages.getString("MigrateOperation.read_only")); //$NON-NLS-1$
            finalMessage = sb.toString();
            severity = MessageDialog.WARNING;
        } else {
            finalMessage = Messages.getString("MigrateOperation.migration_completed"); //$NON-NLS-1$
            severity = MessageDialog.INFORMATION;
        }
        return close(info);
    } finally {
        newDbManager.close(CatalogListener.NORMAL);
    }
}

From source file:com.bdaum.zoom.ui.internal.commands.MigrateCatalogCommand.java

License:Open Source License

@Override
public void run() {
    IDbManager dbManager = Core.getCore().getDbManager();
    File catFile = dbManager.getFile();
    if (catFile != null) {
        Job[] criticalJobs = Job.getJobManager().find(Constants.CRITICAL);
        if (criticalJobs.length > 0) {
            AcousticMessageDialog.openInformation(getShell(), Messages.MigrateCatActionDelegate_cat_migratiion,
                    Messages.MigrateCatActionDelegate_cannot_execute);
            return;
        }//from   w  w w .  j  av a 2 s. c o  m
        MigrateDialog dialog = new MigrateDialog(getShell(), catFile);
        if (dialog.open() == MigrateDialog.OK) {
            final MigrationPolicy policy = dialog.getResult();
            File targetFile = new File(policy.getTargetCatalog());
            if (targetFile.exists() && !AcousticMessageDialog.openQuestion(getShell(),
                    Messages.MigrateCatActionDelegate_cat_migratiion,
                    NLS.bind(Messages.MigrateCatActionDelegate_target_exists, targetFile.getName())))
                return;
            targetFile.delete();
            IDbFactory dbFactory = Core.getCore().getDbFactory();
            final IDbManager newDbManager = dbFactory.createDbManager(policy.getTargetCatalog(), true, false,
                    false);
            IRunnableWithProgress runnable1 = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    CoreActivator.getDefault().getFileWatchManager().setPaused(true,
                            this.getClass().toString());
                    Job.getJobManager().cancel(Constants.FOLDERWATCH);
                    Job.getJobManager().cancel(Constants.SYNCPICASA);
                    Core.waitOnJobCanceled(Constants.FOLDERWATCH, Constants.SYNCPICASA);
                    MigrateOperation op = new MigrateOperation(newDbManager, policy);
                    try {
                        status = op.execute(monitor, MigrateCatalogCommand.this);
                        finalMessage = op.getFinalMessage();
                        severity = op.getSeverity();
                    } catch (ExecutionException e) {
                        status = new Status(IStatus.ERROR, UiActivator.PLUGIN_ID,
                                Messages.MigrateCatActionDelegate_internal_error, e);
                    }
                }
            };
            ZProgressMonitorDialog pm = new ZProgressMonitorDialog(getShell());
            try {
                pm.run(true, true, runnable1);
                if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.CANCEL) {
                    if (status.getSeverity() == IStatus.ERROR) {
                        AcousticMessageDialog.openError(getShell(),
                                Messages.MigrateCatActionDelegate_cat_migratiion,
                                NLS.bind(Messages.MigrateCatActionDelegate_finished_with_problems,
                                        status.toString()));
                    }
                    targetFile.delete();
                    return;
                }
                if (finalMessage == null)
                    finalMessage = ""; //$NON-NLS-1$
                if (status.getSeverity() == IStatus.WARNING) {
                    finalMessage += '\n' + status.getMessage();
                    severity = MessageDialog.WARNING;
                }
                AcousticMessageDialog finalDialog = new AcousticMessageDialog(getShell(),
                        Messages.MigrateCatActionDelegate_catalog_migration, null, finalMessage, severity,
                        new String[] { Messages.MigrateCatActionDelegate_export_preferences,
                                Messages.MigrateCatActionDelegate_done },
                        1);
                if (finalDialog.open() == 0) {
                    ExportPreferencesWizard wizard = new ExportPreferencesWizard();
                    wizard.init(getActiveWorkbenchWindow().getWorkbench(), null);
                    new WizardDialog(getShell(), wizard).open();
                }
            } catch (InvocationTargetException e) {
                UiActivator.getDefault().logError(Messages.MigrateCatActionDelegate_error_migrating, e);
                targetFile.delete();
            } catch (InterruptedException e) {
                targetFile.delete();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                UiActivator.getDefault().postCatInit(false);
                CoreActivator.getDefault().getFileWatchManager().setPaused(false, this.getClass().toString());
            }
        }
    }
}

From source file:com.bdaum.zoom.ui.internal.UiActivator.java

License:Open Source License

public boolean preCatClose(final int mode, String title, String msg, boolean hideShell) {
    closing = true;//from  w w  w .  j ava 2s  . c om
    Job.getJobManager().cancel(Constants.FOLDERWATCH);
    Job.getJobManager().cancel(Constants.SYNCPICASA);
    Job.getJobManager().cancel(Constants.UPDATING);
    Core.waitOnJobCanceled(Constants.FOLDERWATCH, Constants.SYNCPICASA, Constants.UPDATING);
    if (Core.getCore().getDbManager().getFile() == null)
        return true;
    IWorkbench workbench = PlatformUI.getWorkbench();
    Display display = workbench.getDisplay();
    if (mode != CatalogListener.EMERGENCY) {
        IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
        if (criticalJobsRunning()) {
            UiUtilities.showView("org.eclipse.ui.views.ProgressView"); //$NON-NLS-1$
            IInputValidator validator = new IInputValidator() {
                public String isValid(String newText) {
                    return criticalJobsRunning() ? "Jobs running" : null; //$NON-NLS-1$
                }
            };
            final TimedMessageDialog dialog = new TimedMessageDialog(null, validator, title, null,
                    msg + Messages.UiActivator_please_wait, MessageDialog.WARNING,
                    new String[] { Messages.UiActivator_return_to_workbench,
                            Messages.UiActivator_cancel_all_operations },
                    0, 1, 200L);
            if (!display.isDisposed())
                display.syncExec(() -> dialog.open());
            int returnCode = dialog.getReturnCode();
            if (hideShell && returnCode == 0 && activeWorkbenchWindow != null)
                activeWorkbenchWindow.getShell().setVisible(true);
            return returnCode == 1;
        }
        if (hideShell && activeWorkbenchWindow != null)
            activeWorkbenchWindow.getShell().setVisible(false);
    }
    performClosingTasks(mode);
    return true;
}

From source file:com.drgarbage.utils.Messages.java

License:Apache License

public static int warning(Shell shell, String title, String message) {
    MessageDialog dlg = new MessageDialog(shell, title, CoreImg.aboutDrGarbageIcon_16x16.createImage(), message,
            MessageDialog.WARNING, new String[] { IDialogConstants.OK_LABEL }, 0);
    return dlg.open();
}

From source file:com.elphel.vdt.core.options.OptionsCore.java

License:Open Source License

private static void checkVersionCompatibility(Context context, IPreferenceStore store) {
    if (OptionsUtils.isVersionCompatible(context.getVersion(), context.getName(), store))
        return;/*from ww  w  . j a  v  a  2 s .co m*/

    Shell shell = VerilogPlugin.getActiveWorkbenchShell();
    String message = "Version of TSL description has been changed.\nDo you wish to delete stored values?";
    MessageDialog messageBox = new MessageDialog(shell, "Warning", null, message, MessageDialog.WARNING,
            new String[] { "Yes", "No" }, 1);
    messageBox.open();
    if (messageBox.getReturnCode() == 0) {
        OptionsUtils.clearStore(context.getName(), store);
        finalizeDoStore(store);
    }
}

From source file:com.google.dart.tools.ui.actions.FormatAllAction.java

License:Open Source License

@Override
public void run(IStructuredSelection selection) {
    CompilationUnit[] cus = getCompilationUnits(selection);
    if (cus.length == 0) {
        MessageDialog.openInformation(getShell(), ActionMessages.FormatAllAction_EmptySelection_title,
                ActionMessages.FormatAllAction_EmptySelection_description);
        return;//from   w  w w. j  av a2  s  . c  o m
    }
    try {
        if (cus.length == 1) {
            DartUI.openInEditor(cus[0]);
        } else {
            int returnCode = OptionalMessageDialog.open("FormatAll", //$NON-NLS-1$
                    getShell(), ActionMessages.FormatAllAction_noundo_title, null,
                    ActionMessages.FormatAllAction_noundo_message, MessageDialog.WARNING,
                    new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0);
            if (returnCode != OptionalMessageDialog.NOT_SHOWN && returnCode != Window.OK) {
                return;
            }
        }
    } catch (CoreException e) {
        ExceptionHandler.handle(e, getShell(), ActionMessages.FormatAllAction_error_title,
                ActionMessages.FormatAllAction_error_message);
    }
    runOnMultiple(cus);
}

From source file:com.google.dart.tools.ui.internal.text.dart.ContentAssistProcessor.java

License:Open Source License

/**
 * Informs the user about the fact that there are no enabled categories in the default content
 * assist set and shows a link to the preferences.
 *///from   w  w  w  .  j  av a2s.c  o  m
private boolean informUserAboutEmptyDefaultCategory() {
    if (OptionalMessageDialog.isDialogEnabled(PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY)) {
        final Shell shell = DartToolsPlugin.getActiveWorkbenchShell();
        String title = DartTextMessages.ContentAssistProcessor_all_disabled_title;
        String message = DartTextMessages.ContentAssistProcessor_all_disabled_message;
        // see PreferencePage#createControl for the 'defaults' label
        final String restoreButtonLabel = JFaceResources.getString("defaults"); //$NON-NLS-1$
        final String linkMessage = Messages.format(
                DartTextMessages.ContentAssistProcessor_all_disabled_preference_link,
                LegacyActionTools.removeMnemonics(restoreButtonLabel));
        final int restoreId = IDialogConstants.CLIENT_ID + 10;
        final int settingsId = IDialogConstants.CLIENT_ID + 11;
        final OptionalMessageDialog dialog = new OptionalMessageDialog(PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY,
                shell, title, null /*
                                   * default image
                                   */, message, MessageDialog.WARNING,
                new String[] { restoreButtonLabel, IDialogConstants.CLOSE_LABEL }, 1) {
            /*
             * @see org.eclipse.jface.dialogs.MessageDialog#createButtonsForButtonBar
             * (org.eclipse.swt.widgets.Composite)
             */
            @Override
            protected void createButtonsForButtonBar(Composite parent) {
                Button[] buttons = new Button[2];
                buttons[0] = createButton(parent, restoreId, restoreButtonLabel, false);
                buttons[1] = createButton(parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL,
                        true);
                setButtons(buttons);
            }

            /*
             * @see com.google.dart.tools.ui.dialogs.OptionalMessageDialog#createCustomArea
             * (org.eclipse.swt.widgets.Composite)
             */
            @Override
            protected Control createCustomArea(Composite composite) {
                // wrap link and checkbox in one composite without space
                Composite parent = new Composite(composite, SWT.NONE);
                GridLayout layout = new GridLayout();
                layout.marginHeight = 0;
                layout.marginWidth = 0;
                layout.verticalSpacing = 0;
                parent.setLayout(layout);

                Composite linkComposite = new Composite(parent, SWT.NONE);
                layout = new GridLayout();
                layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
                layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
                layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
                linkComposite.setLayout(layout);

                Link link = new Link(linkComposite, SWT.NONE);
                link.setText(linkMessage);
                link.addSelectionListener(new SelectionAdapter() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        setReturnCode(settingsId);
                        close();
                    }
                });
                GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
                gridData.widthHint = this.getMinimumMessageWidth();
                link.setLayoutData(gridData);

                // create checkbox and "don't show this message" prompt
                super.createCustomArea(parent);

                return parent;
            }
        };
        int returnValue = dialog.open();
        if (restoreId == returnValue || settingsId == returnValue) {
            if (restoreId == returnValue) {
                IPreferenceStore store = DartToolsPlugin.getDefault().getPreferenceStore();
                store.setToDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER);
                store.setToDefault(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES);
            }
            if (settingsId == returnValue) {
                PreferencesUtil.createPreferenceDialogOn(shell,
                        "com.google.dart.tools.ui.internal.preferences.CodeAssistPreferenceAdvanced", null, //$NON-NLS-1$
                        null).open();
            }
            CompletionProposalComputerRegistry registry = CompletionProposalComputerRegistry.getDefault();
            registry.reload();
            return true;
        }
    }
    return false;
}

From source file:com.gorillalogic.monkeyconsole.editors.FoneMonkeyTestContributor.java

License:Open Source License

private void createActions(String extention) {
    actions.removeAll(actions);/*from   ww  w. j av a2 s .c o  m*/

    clearToolItem = new Action() {
        public void run() {

            MessageDialog dlg = new MessageDialog(activeEditorPart.getSite().getShell(), "Delete All?",
                    MonkeyTalkImagesEnum.CLEAR.image.createImage(),
                    "Are you sure you would like to delete all items?", MessageDialog.WARNING,
                    new String[] { "Cancel", "OK" }, 1);
            if (dlg.open() == 1)
                FoneMonkeyPlugin.getDefault().getController().clear();
        }
    };
    clearToolItem.setText("Clear");
    clearToolItem.setToolTipText("Clear All");
    clearToolItem.setImageDescriptor(MonkeyTalkImagesEnum.CLEARROW.image);
    clearToolItem.setId("monkeyclear");
    clearToolItem.setEnabled(false);
    actions.add(clearToolItem);

    componentTreeToolItem = new Action() {
        public void run() {
            FoneMonkeyPlugin.getDefault().getController().fetchAndShowComponentTree();
        }
    };
    componentTreeToolItem.setText("View Component Tree");
    componentTreeToolItem.setToolTipText("View Component Tree");
    componentTreeToolItem.setImageDescriptor(MonkeyTalkImagesEnum.TREE.image);
    componentTreeToolItem.setId("refreshtree");
    componentTreeToolItem.setEnabled(false);
    actions.add(componentTreeToolItem);

    actions.add(new Separator());
    // /////////////////////
    // Play Back selection type component
    // /////////////////////
    if (extention.equalsIgnoreCase("mt")) {
        playToolItem = new Action() {
            public void run() {

                if (FoneMonkeyPlugin.getDefault().getController().isRecordingON()) {
                    editor.getFmch().writeToConsole(
                            "WARNING: PlayAll action invoked, but current console window reports recording ON");
                    return;
                }
                if (editor.getActivePage() == 1) {
                    editor.convertFromMonkeyTalk();
                }
                editor.getEditorSite().getWorkbenchWindow().getWorkbench().saveAllEditors(true);
                FoneMonkeyPlugin.getDefault().getController().startReplayAll();
            }
        };
        playToolItem.setText("Play All");
        playToolItem.setToolTipText("Play All");
        playToolItem.setEnabled(false);
        playToolItem.setImageDescriptor(MonkeyTalkImagesEnum.PLAY.image);
        playToolItem.setId("monkeyplay");
        actions.add(playToolItem);
    } else if (extention.equalsIgnoreCase("mts")) {
        playToolItem = new Action() {
            public void run() {
                editor.getEditorSite().getWorkbenchWindow().getWorkbench().saveAllEditors(true);
                FoneMonkeyPlugin.getDefault().getController().startSuiteReplay();
            }
        };
        playToolItem.setText("Run As Suite");
        playToolItem.setToolTipText("Run as a Test Suite");
        playToolItem.setImageDescriptor(MonkeyTalkImagesEnum.PLAY.image);
        playToolItem.setId("monkeyplaysuite");
        playToolItem.setEnabled(false);
        actions.add(playToolItem);
    } else if (extention.equalsIgnoreCase("js")) {
        playToolItem = new Action() {
            public void run() {
                try {
                    jsEditor.getEditorSite().getWorkbenchWindow().getWorkbench().saveAllEditors(true);
                    FoneMonkeyPlugin.getDefault().getController().startJScriptReplay();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        playToolItem.setText("Run Script");
        playToolItem.setToolTipText("Run Script");
        playToolItem.setImageDescriptor(MonkeyTalkImagesEnum.PLAY.image);
        playToolItem.setId("org.eclipse.wst.jsdt.internal.ui.javaeditor.monkeytalk.runaction");
        playToolItem.setEnabled(false);
        actions.add(playToolItem);
    }
    stopToolItem.setText("Stop");
    stopToolItem.setToolTipText("Stop");
    stopToolItem.setEnabled(false);
    stopToolItem.setImageDescriptor(MonkeyTalkImagesEnum.STOP.image);
    stopToolItem.setId("monkeystop");
    actions.add(stopToolItem);

    recordToolItem.setEnabled(false);
    recordToolItem.setText("Record");
    recordToolItem.setToolTipText("Record");
    recordToolItem.setImageDescriptor(MonkeyTalkImagesEnum.RECORDING.image);
    recordToolItem.setId("monkeyrecord");
    actions.add(recordToolItem);

    playOnCloudAction.setText("Submit to Cloud");
    playOnCloudAction.setToolTipText("Submit Job to CloudMonkey");
    playOnCloudAction.setImageDescriptor(MonkeyTalkImagesEnum.PLAYONCLOUD.image);
    playOnCloudAction.setId("monkeyplaysuiteoncloud");
    playOnCloudAction.setEnabled(false);
    actions.add(playOnCloudAction);

    actions.add(new Separator());

    // //////////////////////
    // Connection Component
    // /////////////////////
    List<Action> connectionItems = new ArrayList<Action>();

    // ////////////
    connectionDropdown = new DropDownMenuAction(connectionItems) {

    };
    connectionDropdown.setId("monkeyconnect");
    actions.add(connectionDropdown);

    // ////////////////////////////////////

    connectToAndroidEmulatorTethered = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.EMULATOR,
            "Android Emulator/Tethered Device", MonkeyTalkImagesEnum.CONNECTANDROIDEMULATOR.image);
    if (new Boolean(FoneMonkeyPlugin.getDefault().getPreferenceStore()
            .getString(PreferenceConstants.P_INCLUDEANDROID))) {
        connectionItems.add(connectToAndroidEmulatorTethered);
    }

    // ///////////////
    connectToiOSSimulator = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.SIMULATOR,
            "iOS Simulator", MonkeyTalkImagesEnum.CONNECTIOSEMMULATOR.image);
    if (new Boolean(
            FoneMonkeyPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_INCLUDEIOS))) {
        connectionItems.add(connectToiOSSimulator);
    }

    // ////////////////////////////////////////////////////////
    connectNetworked = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.NETWORKED_ANDROID,
            "Networked Android Device...", MonkeyTalkImagesEnum.CONNECTNETWORKEDANDROID.image) {
        @Override
        public void doRun(MonkeyTalkController controller) {
            String host = controller.getHost(true);
            if (host != null) {
                this.setText("Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST));
                this.setToolTipText(
                        "Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST));
                controller.connect(ConnectionTypesEnum.NETWORKED_ANDROID);
                controller.setHost(host);
            }
        }
    };
    if (new Boolean(FoneMonkeyPlugin.getDefault().getPreferenceStore()
            .getString(PreferenceConstants.P_INCLUDEANDROID))) {
        connectionItems.add(connectNetworked);
    }
    // ////////////////////////////////////////////////////////
    connectCloud = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.CLOUD_ANDROID,
            "CloudMonkey Android Emulator", MonkeyTalkImagesEnum.CONNECTCLOUDMONKEY.image) {
        public void doRun(MonkeyTalkController controller) {
            String host = controller.getCloudHost();
            if (host != null) {
                connectCloud.setText("CloudMonkey at "
                        + controller.preferenceStore.getString(PreferenceConstants.C_CLOUD_HOST));
                connectCloud.setToolTipText("CloudMonkey at "
                        + controller.preferenceStore.getString(PreferenceConstants.C_CLOUD_HOST));

                controller.setHost(host);
                controller.connect(ConnectionTypesEnum.CLOUD_ANDROID);
            }
        }
    };
    if (new Boolean(FoneMonkeyPlugin.getDefault().getPreferenceStore()
            .getString(PreferenceConstants.P_INCLUDEANDROID))) {
        // Uncomment to enable interactive record/playback on Cloud
        // connectionItems.add(connectCloud);
    }

    connectNetworkedIos = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.NETWORKED_IOS,
            "Networked iOS Device...", MonkeyTalkImagesEnum.CONNECTNETWORKEDIOS.image) {
        public void doRun(MonkeyTalkController controller) {
            String host = controller.getHost(true);
            if (host != null) {
                connectNetworkedIos.setText(
                        "Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST));
                connectNetworkedIos.setToolTipText(
                        "Device at " + controller.preferenceStore.getString(PreferenceConstants.C_HOST));

                controller.connect(ConnectionTypesEnum.NETWORKED_IOS);
                controller.setHost(host);
            }
        }
    };
    if (new Boolean(
            FoneMonkeyPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_INCLUDEIOS))) {
        connectionItems.add(connectNetworkedIos);
    }
    noDeviceSelected = new ConnectionItem(connectionDropdown, ConnectionTypesEnum.NO_DEVICE,
            "No Device Selected", MonkeyTalkImagesEnum.NOCONNECTION.image);

    connectionItems.add(noDeviceSelected);

    if (connectionDropdown != null && connectionItems.size() > 0) {
        connectionDropdown.setSelectedAction(connectionItems.get(0));
    }
    setupFilterDropdown(actions);
    Action webAction = new Action() {
        public void run() {
            URL webUrl;
            try {
                webUrl = new URL("http://www.gorillalogic.com/testing-tools/support-services");
            } catch (MalformedURLException e) {
                return;
            }
            try {
                IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport()
                        .createBrowser("GorillaLogic");
                browser.openURL(webUrl);
            } catch (PartInitException e) {
                return;
            }
        }
    };
    webAction.setToolTipText("Having trouble getting started? Let us help!"); //$NON-NLS-1$
    ImageDescriptor newImage = FoneMonkeyPlugin.getImageDescriptor("icons/gl-icon-16.png");
    webAction.setImageDescriptor(newImage); //$NON-NLS-1$
    webAction.setId("monkeycontactus");
    actions.add(webAction);

    // //////////////////////////////////////////////////////////////////////////
    // / Section for configuration options
    // //////////////////////////////////////////////////////////////////////////

    actions.add(new Separator());

    // This action setup the thinktime and timeout
    Action timeSetupAction = new Action() {
        public void run() {
            TimeSetupWizard wizard = new TimeSetupWizard();
            WizardDialog dialog = new WizardDialog(new Shell(), wizard);
            dialog.create();
            dialog.open();

        }
    };
    timeSetupAction.setToolTipText("Thinktime/Timeout setup");
    timeSetupAction.setImageDescriptor(MonkeyTalkImagesEnum.TIME.image); //$NON-NLS-1$
    timeSetupAction.setId("monkeytimeSetup");
    actions.add(timeSetupAction);

    // This action is to set up if the execution should take screenshots on errors

    Action screenshotOnErrorAction = new Action() {
        public void run() {
            FoneMonkeyPlugin.getDefault().getPreferenceStore()
                    .setValue(PreferenceConstants.P_TAKEERRORSCREENSHOTS, this.isChecked());
        }
    };

    screenshotOnErrorAction.setImageDescriptor(MonkeyTalkImagesEnum.SCREENSHOTERROR.image);

    if (FoneMonkeyPlugin.getDefault().getPreferenceStore()
            .getBoolean(PreferenceConstants.P_TAKEERRORSCREENSHOTS)) {
        screenshotOnErrorAction.setChecked(true);
    } else {
        screenshotOnErrorAction.setChecked(false);
    }

    screenshotOnErrorAction.setToolTipText("Take screenshot on error.");
    screenshotOnErrorAction.setId("monkeyScreenshotOnError");

    actions.add(screenshotOnErrorAction);

    // This action is to set up the taking of screenshots while executing commands
    Action takeScreenshot = new Action() {
        public void run() {
            FoneMonkeyPlugin.getDefault().getPreferenceStore()
                    .setValue(PreferenceConstants.P_TAKEAFTERSCREENSHOTS, this.isChecked());

        }
    };
    takeScreenshot.setImageDescriptor(MonkeyTalkImagesEnum.SCREENSHOT.image);

    if (FoneMonkeyPlugin.getDefault().getPreferenceStore()
            .getBoolean(PreferenceConstants.P_TAKEAFTERSCREENSHOTS)) {
        takeScreenshot.setChecked(true);
    } else {
        takeScreenshot.setChecked(false);
    }

    takeScreenshot.setToolTipText("Take screenchots on command execution.");
    takeScreenshot.setId("monkeyTakeScreenShot");

    actions.add(takeScreenshot);

}