Example usage for org.eclipse.jface.dialogs IDialogConstants CANCEL_LABEL

List of usage examples for org.eclipse.jface.dialogs IDialogConstants CANCEL_LABEL

Introduction

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

Prototype

String CANCEL_LABEL

To view the source code for org.eclipse.jface.dialogs IDialogConstants CANCEL_LABEL.

Click Source Link

Document

The label for cancel buttons.

Usage

From source file:com.bdaum.zoom.ui.internal.actions.DeleteAction.java

License:Open Source License

@Override
public void run() {
    SmartCollectionImpl selectedCollection = Ui.getUi()
            .getNavigationHistory(adaptable.getAdapter(IWorkbenchWindow.class)).getSelectedCollection();
    boolean inAlbum = false;
    SmartCollection sm = selectedCollection;
    while (sm != null) {
        if (sm.getAlbum() && !sm.getSystem()) {
            inAlbum = true;/*from w  w w . ja  v  a2s  .co m*/
            break;
        }
        sm = sm.getSmartCollection_subSelection_parent();
    }
    AssetSelection selection = adaptable.getAdapter(AssetSelection.class);
    List<SlideImpl> slides = null;
    List<ExhibitImpl> exhibits = null;
    List<WebExhibitImpl> webexhibits = null;
    if (selection != null) {
        List<Asset> localAssets = selection.getLocalAssets();
        if (localAssets != null && !localAssets.isEmpty()) {
            ICore core = Core.getCore();
            IVolumeManager volumeManager = core.getVolumeManager();
            IDbManager dbManager = core.getDbManager();
            if (localAssets.size() == 1) {
                Asset asset = localAssets.get(0);
                String assetId = asset.getStringId();
                // Check XRef
                slides = dbManager.obtainObjects(SlideImpl.class, "asset", assetId, QueryField.EQUALS); //$NON-NLS-1$
                exhibits = dbManager.obtainObjects(ExhibitImpl.class, "asset", assetId, QueryField.EQUALS); //$NON-NLS-1$
                webexhibits = dbManager.obtainObjects(WebExhibitImpl.class, "asset", assetId, //$NON-NLS-1$
                        QueryField.EQUALS);
                if (!slides.isEmpty() || !exhibits.isEmpty() || !webexhibits.isEmpty()) {
                    Set<String> presentationIds = new HashSet<String>(7);
                    for (SlideImpl slide : slides) {
                        presentationIds.add(slide.getSlideShow_entry_parent());
                        if (presentationIds.size() > 4)
                            break;
                    }
                    for (ExhibitImpl exhibit : exhibits) {
                        if (presentationIds.size() > 4)
                            break;
                        WallImpl wall = dbManager.obtainById(WallImpl.class, exhibit.getWall_exhibit_parent());
                        if (wall != null) {
                            Exhibition exhibition = wall.getExhibition_wall_parent();
                            if (exhibition != null)
                                presentationIds.add(exhibition.toString());
                        }
                    }
                    for (WebExhibitImpl webexhibit : webexhibits) {
                        if (presentationIds.size() > 4)
                            break;
                        StoryboardImpl story = dbManager.obtainById(StoryboardImpl.class,
                                webexhibit.getStoryboard_exhibit_parent());
                        if (story != null) {
                            WebGallery gallery = story.getWebGallery_storyboard_parent();
                            if (gallery != null)
                                presentationIds.add(gallery.toString());
                        }
                    }
                    StringBuilder sb = new StringBuilder();
                    int i = 0;
                    for (String id : presentationIds) {
                        if (++i > 3) {
                            sb.append(",... "); //$NON-NLS-1$
                            break;
                        }
                        IdentifiableObject obj = dbManager.obtainById(IdentifiableObject.class, id);
                        if (obj instanceof SlideShowImpl) {
                            if (i > 1)
                                sb.append(", "); //$NON-NLS-1$
                            sb.append(NLS.bind(Messages.DeleteAction_Slide_show,
                                    ((SlideShowImpl) obj).getName()));
                        } else if (obj instanceof ExhibitionImpl) {
                            if (i > 1)
                                sb.append(", "); //$NON-NLS-1$
                            sb.append(NLS.bind(Messages.DeleteAction_Exhibition,
                                    ((ExhibitionImpl) obj).getName()));
                        } else if (obj instanceof WebGalleryImpl) {
                            if (i > 1)
                                sb.append(", "); //$NON-NLS-1$
                            sb.append(NLS.bind(Messages.DeleteAction_Web_gallery,
                                    ((WebGalleryImpl) obj).getName()));
                        }
                    }
                    StringBuilder message = new StringBuilder();
                    message.append(NLS.bind(Messages.DeleteAction_image_used_in, sb))
                            .append(i == 1 ? Messages.DeleteAction_remove_image_singular
                                    : Messages.DeleteAction_remove_image_plural)
                            .append(Messages.DeleteAction_operation_cannot_be_undome);
                    if (!AcousticMessageDialog.openConfirm(shell, Messages.DeleteAction_used_in_artifacts,
                            message.toString()))
                        return;
                }
                URI fileUri = volumeManager.findExistingFile(asset, true);
                if (fileUri == null) {
                    // Image file does not exist
                    if (!volumeManager.isOffline(asset.getVolume())) {
                        if (inAlbum) {
                            MessageDialog dialog = new AcousticMessageDialog(shell,
                                    Messages.DeleteAction_deleting_images, null,
                                    Messages.DeleteAction_delete_remote_entries, MessageDialog.QUESTION,
                                    new String[] { Messages.DeleteAction_remove_from_album,
                                            Messages.DeleteAction_delete_only_cat,
                                            IDialogConstants.CANCEL_LABEL },
                                    0);
                            if (dialog.open() != 2)
                                launchOperation(selectedCollection, false, Collections.singletonList(asset),
                                        slides, exhibits, webexhibits);
                        } else if (AcousticMessageDialog.openConfirm(shell,
                                Messages.DeleteAction_deleting_images,
                                NLS.bind(Messages.DeleteAction_delete_cat_entry, asset.getName())))
                            launchOperation(null, false, Collections.singletonList(asset), slides, exhibits,
                                    webexhibits);
                        return;
                    }
                } else {
                    File file = new File(fileUri);
                    if (!file.canWrite()) {
                        if (inAlbum) {
                            MessageDialog dialog = new AcousticMessageDialog(shell,
                                    Messages.DeleteAction_deleting_images, null,
                                    Messages.DeleteAction_delete_write_protected, MessageDialog.QUESTION,
                                    new String[] { Messages.DeleteAction_remove_from_album,
                                            Messages.DeleteAction_delete_only_cat,
                                            IDialogConstants.CANCEL_LABEL },
                                    0);
                            if (dialog.open() != 2)
                                launchOperation(selectedCollection, false, Collections.singletonList(asset),
                                        slides, exhibits, webexhibits);
                        } else if (AcousticMessageDialog.openConfirm(shell,
                                Messages.DeleteAction_deleting_images,
                                NLS.bind(Messages.DeleteAction_delete_cat_entry_write_protected,
                                        asset.getName())))
                            launchOperation(null, false, Collections.singletonList(asset), slides, exhibits,
                                    webexhibits);
                        return;
                    }
                }
            } else {
                String[] assetIds = selection.getLocalAssetIds();
                slides = dbManager.obtainObjects(SlideImpl.class, "asset", assetIds); //$NON-NLS-1$
                exhibits = dbManager.obtainObjects(ExhibitImpl.class, "asset", assetIds); //$NON-NLS-1$
                webexhibits = dbManager.obtainObjects(WebExhibitImpl.class, "asset", assetIds); //$NON-NLS-1$
                if ((!slides.isEmpty() || !exhibits.isEmpty() || !webexhibits.isEmpty())
                        && !AcousticMessageDialog.openConfirm(shell, Messages.DeleteAction_used_in_artifacts,
                                Messages.DeleteAction_images_used_in_presentations))
                    return;
            }
            boolean fileOnDisc = false;
            for (Asset asset : localAssets) {
                URI uri = volumeManager.findExistingFile(asset, true);
                if (uri != null && !volumeManager.isOffline(asset.getVolume()) && new File(uri).canWrite()) {
                    fileOnDisc = true;
                    break;
                }
            }
            int esc = 1;
            List<String> buttons = new ArrayList<String>();
            if (inAlbum) {
                buttons.add(Messages.DeleteAction_remove_from_album);
                ++esc;
            }
            buttons.add(Messages.DeleteAction_delete_only_cat);
            if (fileOnDisc) {
                buttons.add(Messages.DeleteAction_delete_on_disc_too);
                ++esc;
            }
            buttons.add(IDialogConstants.CANCEL_LABEL);
            MessageDialog dialog = new AcousticMessageDialog(shell, Messages.DeleteAction_deleting_images, null,
                    (fileOnDisc) ? Messages.DeleteAction_delete_images + Messages.DeleteAction_delete_on_disk
                            : Messages.DeleteAction_delete_images,
                    MessageDialog.QUESTION, buttons.toArray(new String[buttons.size()]), 0);
            int ret = dialog.open();
            if (ret < esc)
                launchOperation(ret == 0 && inAlbum ? selectedCollection : null,
                        inAlbum ? (ret > 1) : (ret > 0), localAssets, slides, exhibits, webexhibits);
        }
    }
}

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

License:Open Source License

public void doRun() {
    StorageObject[] dcims;/*from   w  w  w  .  j  a  v  a  2 s . c  o  m*/
    while (true) {
        dcims = Core.getCore().getVolumeManager().findDCIMs();
        if (dcims.length > 0)
            break;
        MessageDialog dialog = new AcousticMessageDialog(getShell(),
                Messages.ImportFromDeviceAction_Import_from_device, null,
                Messages.ImportFromDeviceAction_there_seems_no_suitable_device, MessageDialog.QUESTION,
                new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.CANCEL_LABEL }, 1);
        if (dialog.open() > 0)
            return;
    }
    ImportFromDeviceWizard wizard = new ImportFromDeviceWizard(null, dcims, true, true, true, null, false);
    WizardDialog wizardDialog = new WizardDialog(getShell(), wizard);
    wizard.init(null, null);
    wizardDialog.open();
}

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

License:Open Source License

@Override
public void run() {
    AcousticMessageDialog includeDialog = new AcousticMessageDialog(getShell(),
            Messages.FindOrphansActionDelegate_search_orphans, null,
            Messages.FindOrphansActionDelegate_include_off_line, AcousticMessageDialog.QUESTION, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            1);//from w  w  w  .  j  av a2s .  co  m
    final int ret = includeDialog.open();
    if (ret >= 2)
        return;
    isCanceled = false;
    ZProgressMonitorDialog dialog = new ZProgressMonitorDialog(getShell());
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            ICore core = Core.getCore();
            IVolumeManager volumeManager = core.getVolumeManager();
            List<AssetImpl> set = core.getDbManager().obtainAssets();
            monitor.beginTask(Messages.FindOrphansActionDelegate_scanning_catalog, set.size());
            for (AssetImpl asset : set) {
                URI uri = volumeManager.findExistingFile(asset, false);
                if (uri == null) {
                    if (ret == 0 || !volumeManager.isOffline(asset.getVolume()))
                        result.add(asset);
                    else {
                        String volume = asset.getVolume();
                        if (volume != null && !volume.isEmpty())
                            volumes.add(volume);
                    }
                }
                if (monitor.isCanceled()) {
                    isCanceled = true;
                    break;
                }
                monitor.worked(1);
            }
            monitor.done();
        }
    };
    if (isCanceled)
        return;
    try {
        String v = null;
        if (!volumes.isEmpty()) {
            String[] vols = volumes.toArray(new String[volumes.size()]);
            Arrays.sort(vols);
            StringBuffer sb = new StringBuffer();
            for (String volume : vols) {
                if (sb.length() > 0)
                    sb.append(", "); //$NON-NLS-1$
                sb.append(volume);
            }
            v = sb.toString();
        }
        dialog.run(true, true, runnable);
        if (result.isEmpty()) {
            String message = Messages.FindOrphansActionDelegate_no_orphans_found;
            if (ret == 1 && v != null)
                message += NLS.bind(Messages.FindOrphansActionDelegate_entries_not_checked, v);
            AcousticMessageDialog.openInformation(getShell(), Messages.FindOrphansActionDelegate_orphan_search,
                    message);
        } else {
            boolean show = true;
            if (v != null) {
                String message = NLS.bind(Messages.FindOrphansActionDelegate_n_entries_found, result.size());
                if (ret == 1)
                    message += NLS.bind(Messages.FindOrphansActionDelegate_entries_not_checked, v);
                show = AcousticMessageDialog.openConfirm(getShell(),
                        Messages.FindOrphansActionDelegate_orphan_search, message);
            }
            if (show) {
                SmartCollectionImpl collection = new SmartCollectionImpl(
                        Messages.FindOrphansActionDelegate_orphans, true, false, true, false, null, 0, null, 0,
                        null, Constants.INHERIT_LABEL, null, 0, null);
                collection.addCriterion(
                        new CriterionImpl(ICollectionProcessor.ORPHANS, null, result, QueryField.XREF, false));
                Ui.getUi().getNavigationHistory(getActiveWorkbenchWindow())
                        .postSelection(new StructuredSelection(collection));
            }
        }
    } catch (InvocationTargetException e) {
        UiActivator.getDefault().logError(Messages.FindOrphansActionDelegate_error_scanning_for_orphans, e);
    } catch (InterruptedException e) {
        // nothing to do
    }
}

From source file:com.bdaum.zoom.ui.internal.dialogs.AssociationWarningDialog.java

License:Open Source License

public AssociationWarningDialog(Shell parentShell, String dialogTitle, String dialogMessage, String extension) {
    super(parentShell, dialogTitle, null, dialogMessage, WARNING, new String[] {
            Messages.AssociationWarningDialog_Configure_file_assos, IDialogConstants.CANCEL_LABEL }, 0);
    this.extension = extension;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.CategorizeDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    if (size > 1) {
        createButton(parent, BACK_ID, Messages.CategorizeDialog_back,
                Messages.CategorizeDialog_previous_tooltip, false);
        createButton(parent, NEXT_ID, Messages.CategorizeDialog_next, Messages.CategorizeDialog_next_tooltip,
                false);//from w w w  .j a  va  2s .c  o  m
        createButton(parent, CLONE_ID, Messages.CategorizeDialog_clone, Messages.CategorizeDialog_clone_tooltip,
                true);
    }
    createButton(parent, DONE_ID, Messages.CategorizeDialog_done, Messages.CategorizeDialog_done_tooltip, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL,
            Messages.CategorizeDialog_cancel_tooltip, false);
}

From source file:com.bdaum.zoom.ui.internal.dialogs.PurgeEmptyDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, UNDO, Messages.PurgeEmptyDialog_undo, false).setEnabled(false);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

From source file:com.bdaum.zoom.ui.internal.dialogs.VoiceNoteDialog.java

License:Open Source License

private void importFile(IDialogSettings settings) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    switch (tabFolder.getSelectionIndex()) {
    case VOICE:/*from   ww w  .j  av a  2s. co  m*/
        int l = Constants.SupportedSoundFileExtensions.length;
        String[] supportedsoundfileextensions = new String[l];
        for (int i = 0; i < l - 1; i++)
            supportedsoundfileextensions[i] = Constants.SupportedSoundFileExtensions[i] + ";" //$NON-NLS-1$
                    + supportedsoundfileextensions[i].toUpperCase();
        supportedsoundfileextensions[l - 1] = Constants.SupportedSoundFileExtensions[l - 1];
        dialog.setFilterExtensions(supportedsoundfileextensions);
        dialog.setFilterNames(Constants.SupportedSoundFileNames);
        String soundFile = settings.get(SOUNDFILE);
        if (soundFile != null)
            dialog.setFileName(soundFile);
        String file = dialog.open();
        if (file != null) {
            settings.put(SOUNDFILE, file);
            outputFile = new File(file);
            targetUri = sourceUri = outputFile.toURI().toString();
            dirty = true;
            updateButtons();
        }
        return;
    case TEXT:
        dialog.setFilterExtensions(new String[] { "*.txt;*.TXT" }); //$NON-NLS-1$
        dialog.setFilterNames(new String[] { Messages.VoiceNoteDialog_textfiles });
        String textFile = settings.get(TEXTFILE);
        if (textFile != null)
            dialog.setFileName(textFile);
        file = dialog.open();
        if (file != null) {
            settings.put(TEXTFILE, file);
            try {
                String s = readTextfile(file);
                int ret = 1;
                if (!note.getText().isEmpty()) {
                    AcousticMessageDialog mdialog = new AcousticMessageDialog(getShell(),
                            Messages.VoiceNoteDialog_overwrite_text, null, Messages.VoiceNoteDialog_text_exists,
                            MessageDialog.QUESTION_WITH_CANCEL, new String[] { Messages.VoiceNoteDialog_append,
                                    Messages.VoiceNoteDialog_overwrite, IDialogConstants.CANCEL_LABEL },
                            0);
                    ret = mdialog.open();
                    if (ret == 2)
                        return;
                }
                note.setText(ret == 1 ? s : note.getText() + '\n' + s);
                dirty = true;
                updateButtons();
            } catch (IOException e1) {
                note.setText(Messages.VoiceNoteDialog_io_error);
            }
        }
        return;
    case DRAWING:
        dialog.setFilterExtensions(new String[] { "*.zdrw" }); //$NON-NLS-1$
        dialog.setFilterNames(new String[] { NLS.bind(Messages.VoiceNoteDialog_zdrw, Constants.APPNAME) });
        textFile = settings.get(SVGFILE);
        if (textFile != null)
            dialog.setFileName(textFile);
        file = dialog.open();
        if (file != null) {
            settings.put(SVGFILE, file);
            try {
                String s = readTextfile(file);
                int ret = 1;
                if (paintExample.hasVectorFigure()) {
                    AcousticMessageDialog mdialog = new AcousticMessageDialog(getShell(),
                            Messages.VoiceNoteDialog_overwrite_drawing, null,
                            Messages.VoiceNoteDialog_drawing_exists, MessageDialog.QUESTION_WITH_CANCEL,
                            new String[] { Messages.VoiceNoteDialog_append, Messages.VoiceNoteDialog_overwrite,
                                    IDialogConstants.CANCEL_LABEL },
                            0);
                    ret = mdialog.open();
                    if (ret == 2)
                        return;
                }
                paintExample.importSvg(s, ret == 1);
                dirty = true;
                updateButtons();
            } catch (IOException e1) {
                AcousticMessageDialog.openError(getShell(), Messages.VoiceNoteDialog_error_reading_drawing,
                        NLS.bind(Messages.VoiceNoteDialog_io_error_reading_drawing, e1));
            } catch (ParserConfigurationException | SAXException e) {
                AcousticMessageDialog.openError(getShell(), Messages.VoiceNoteDialog_error_reading_drawing,
                        NLS.bind(Messages.VoiceNoteDialog_invalid_drawing, e));
            }
        }
    }
}

From source file:com.bdaum.zoom.ui.internal.preferences.FileExtensionDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    okButton.setEnabled(false);//from   w  w w.java 2  s .com
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

From source file:com.bdaum.zoom.ui.internal.views.ExhibitionView.java

License:Open Source License

private void generate() {
    ExhibitionImpl show = getExhibition();
    if (show == null)
        return;//from w w  w. j  a  va  2 s . c om
    if (offlineImages != null && !offlineImages.isEmpty()) {
        String[] volumes = offlineImages.toArray(new String[offlineImages.size()]);
        Arrays.sort(volumes);
        AcousticMessageDialog.openInformation(getSite().getShell(),
                Messages.getString("ExhibitionView.images_offline"), //$NON-NLS-1$
                volumes.length > 1 ? NLS.bind(Messages.getString("ExhibitionView.volumes_offline"), //$NON-NLS-1$
                        Core.toStringList(volumes, ", ")) //$NON-NLS-1$
                        : NLS.bind(Messages.getString("ExhibitionView.volume_offline"), //$NON-NLS-1$
                                volumes[0]));
        return;
    }
    String s = exhibition.getStringId();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (Character.isLetterOrDigit(c))
            sb.append(c);
    }
    String exhibitionId = sb.toString();
    boolean isFtp = show.getIsFtp();
    String outputFolder = (isFtp) ? show.getFtpDir() : show.getOutputFolder();
    while (outputFolder == null || outputFolder.isEmpty()) {
        show = ExhibitionEditDialog.open(getSite().getShell(), null, show, show.getName(), false,
                Messages.getString("ExhibitionView.please_specify_target")); //$NON-NLS-1$
        if (show == null)
            return;
        isFtp = show.getIsFtp();
        outputFolder = (isFtp) ? show.getFtpDir() : show.getOutputFolder();
    }
    boolean makeDefault = false;
    boolean askForDefault = false;
    final File file = new File(outputFolder);
    if (!isFtp && file.exists() && file.listFiles().length > 0) {
        AcousticMessageDialog dialog;
        File resFile = new File(file, "res"); //$NON-NLS-1$
        File[] rooms = resFile.listFiles(new FileFilter() {
            public boolean accept(File f) {
                return f.getName().startsWith("room_"); //$NON-NLS-1$
            }
        });
        if (rooms.length > 0) {
            File roomFile = new File(resFile, "room_" //$NON-NLS-1$
                    + exhibitionId);
            if (roomFile.exists()) {
                askForDefault = rooms.length > 1;
                dialog = new AcousticMessageDialog(getSite().getShell(),
                        Messages.getString("ExhibitionView.overwriteTitle"), //$NON-NLS-1$
                        null, NLS.bind(Messages.getString("ExhibitionView.exhibition_exists"), file), //$NON-NLS-1$
                        MessageDialog.QUESTION, new String[] { Messages.getString("ExhibitionView.overwrite"), //$NON-NLS-1$
                                Messages.getString("ExhibitionView.clear_folder"), //$NON-NLS-1$
                                IDialogConstants.CANCEL_LABEL },
                        0);
            } else {
                askForDefault = true;
                dialog = new AcousticMessageDialog(getSite().getShell(),
                        Messages.getString("ExhibitionView.add"), //$NON-NLS-1$
                        null, NLS.bind(Messages.getString("ExhibitionView.other_exhibitions"), file), //$NON-NLS-1$
                        MessageDialog.QUESTION, new String[] { Messages.getString("ExhibitionView.add_room"), //$NON-NLS-1$
                                Messages.getString("ExhibitionView.clear_folder"), //$NON-NLS-1$
                                IDialogConstants.CANCEL_LABEL },
                        0);
            }
        } else
            dialog = new AcousticMessageDialog(getSite().getShell(),
                    Messages.getString("ExhibitionView.overwriteTitle"), //$NON-NLS-1$
                    null, NLS.bind(Messages.getString("ExhibitionView.not_empty"), file), //$NON-NLS-1$
                    MessageDialog.QUESTION, new String[] { Messages.getString("ExhibitionView.overwrite"), //$NON-NLS-1$
                            Messages.getString("ExhibitionView.clear_folder"), //$NON-NLS-1$
                            IDialogConstants.CANCEL_LABEL },
                    0);
        int ret = dialog.open();
        switch (ret) {
        case 2:
            return;
        case 1:
            Core.deleteFileOrFolder(file);
            break;
        }
    }
    if (askForDefault)
        makeDefault = AcousticMessageDialog.openQuestion(getSite().getShell(),
                Messages.getString("ExhibitionView.exhibition_start"), //$NON-NLS-1$
                Messages.getString("ExhibitionView.start_viewing")); //$NON-NLS-1$
    String page = show.getPageName();
    final boolean ftp = isFtp;
    final File start = new File(file, (page == null || page.isEmpty()) ? "index.html" //$NON-NLS-1$
            : page);
    final ExhibitionJob job = new ExhibitionJob(show, exhibitionId, ExhibitionView.this, makeDefault);
    final FtpAccount account;
    if (ftp) {
        account = FtpAccount.findAccount(outputFolder);
        if (account == null) {
            AcousticMessageDialog.openError(getSite().getShell(),
                    Messages.getString("ExhibitionView.account_not_existing"), //$NON-NLS-1$
                    NLS.bind(Messages.getString("ExhibitionView.account_not_defined"), //$NON-NLS-1$
                            outputFolder));
            return;
        }
    } else
        account = null;
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            if (!job.wasAborted()) {
                if (ftp)
                    new TransferJob(job.getTargetFolder().listFiles(), account, true).schedule(0);
                else
                    showExhibition(start);
            }
        }

    });
    job.schedule();
}

From source file:com.bdaum.zoom.ui.internal.views.WebGalleryView.java

License:Open Source License

private boolean createGenerator(WebGalleryImpl show, IConfigurationElement el, String outputFolder,
        boolean isFtp, final boolean save) {
    try {/*from w w  w.  jav a2  s.  c o m*/
        Storyboard selectedStoryboard = null;
        if (!Boolean.parseBoolean(el.getAttribute("sections")) && show.getStoryboard().size() > 1) { //$NON-NLS-1$
            SelectStoryBoardDialog dialog = new SelectStoryBoardDialog(getSite().getShell(),
                    Messages.getString("WebGalleryView.multiple_storyboards"), //$NON-NLS-1$
                    NLS.bind(Messages.getString("WebGalleryView.does_not_support_multiple_storyboards"), //$NON-NLS-1$
                            el.getAttribute("name")), //$NON-NLS-1$
                    show.getStoryboard());
            if (dialog.open() != SelectStoryBoardDialog.OK)
                return true;
            selectedStoryboard = dialog.getResult();
        }
        String maxImages = el.getAttribute("maxImages"); //$NON-NLS-1$
        if (maxImages != null) {
            try {
                int max = Integer.parseInt(maxImages);
                int n = 0;
                for (Storyboard storyboard : show.getStoryboard())
                    max -= storyboard.getExhibit().size();
                if (n > max && !AcousticMessageDialog.openQuestion(getSite().getShell(),
                        Messages.getString("WebGalleryView.too_many"), //$NON-NLS-1$
                        NLS.bind(Messages.getString("WebGalleryView.n_exceeds_max"), //$NON-NLS-1$
                                new Object[] { n, max, el.getAttribute("name") }))) //$NON-NLS-1$
                    return true;
            } catch (NumberFormatException e) {
                // ignore
            }
        }
        String aspectRatio = el.getAttribute("aspectRatio"); //$NON-NLS-1$
        if (aspectRatio != null) {
            aspectRatio.trim();
            if (!aspectRatio.isEmpty()) {
                double sample = Double.NaN;
                double tolerance = 5;
                int p = aspectRatio.indexOf(' ');
                if (p > 0) {
                    try {
                        sample = Double.parseDouble(aspectRatio.substring(0, p));
                    } catch (NumberFormatException e) {
                        // Leave at NaN
                    }
                    aspectRatio = aspectRatio.substring(p + 1);
                }
                if (aspectRatio.endsWith("%")) { //$NON-NLS-1$
                    try {
                        tolerance = Double.parseDouble(aspectRatio.substring(0, aspectRatio.length() - 1));
                    } catch (NumberFormatException e) {
                        // Leave at 5
                    }
                }
                List<String> errands = new ArrayList<>();
                IDbManager dbManager = Core.getCore().getDbManager();
                lp: for (Storyboard storyboard : show.getStoryboard()) {
                    for (String exhibitId : storyboard.getExhibit()) {
                        WebExhibitImpl exhibit = dbManager.obtainById(WebExhibitImpl.class, exhibitId);
                        if (exhibit != null) {
                            AssetImpl asset = dbManager.obtainAsset(exhibit.getAsset());
                            if (asset != null & asset.getHeight() > 0) {
                                double prop = (double) asset.getWidth() / asset.getHeight();
                                if (Double.isNaN(sample))
                                    sample = prop;
                                else if (Math.abs(sample - prop) > sample * tolerance / 100d) {
                                    if (p > 0)
                                        errands.add((asset.getName()));
                                    else {
                                        if (!AcousticMessageDialog.openQuestion(getSite().getShell(),
                                                Messages.getString("WebGalleryView.unequal_proportions"), //$NON-NLS-1$
                                                NLS.bind(
                                                        Messages.getString(
                                                                "WebGalleryView.unequal_proportions_msg"), //$NON-NLS-1$
                                                        el.getAttribute("name")))) //$NON-NLS-1$
                                            return true;
                                        break lp;
                                    }
                                }
                            }
                        }
                    }
                }
                if (!errands.isEmpty()
                        && !AcousticMessageDialog
                                .openQuestion(getSite().getShell(),
                                        Messages.getString("WebGalleryView.unequal_proportions"), //$NON-NLS-1$
                                        NLS.bind(Messages.getString("WebGalleryView.required_aspect_ratio"), //$NON-NLS-1$
                                                new Object[] { el.getAttribute("name"), sample, //$NON-NLS-1$
                                                        Core.toStringList(errands.toArray(new String[errands.size()]),
                                                                ", ") }))) //$NON-NLS-1$
                    return true;
            }
        }
        final IGalleryGenerator generator = (IGalleryGenerator) el.createExecutableExtension("class"); //$NON-NLS-1$
        if (generator instanceof AbstractGalleryGenerator) {
            ((AbstractGalleryGenerator) generator).setConfigurationElement(el);
            ((AbstractGalleryGenerator) generator).setSelectedStoryBoard(selectedStoryboard);
        }
        final File file = new File(outputFolder);
        if (!isFtp && file.exists() && file.listFiles().length > 0) {
            AcousticMessageDialog dialog = new AcousticMessageDialog(getSite().getShell(),
                    Messages.getString("WebGalleryView.overwrite"), //$NON-NLS-1$
                    null, NLS.bind(Messages.getString("WebGalleryView.output_folder_not_empty"), file), //$NON-NLS-1$
                    MessageDialog.QUESTION,
                    new String[] { Messages.getString("WebGalleryView.overwrite_button"), //$NON-NLS-1$
                            Messages.getString("WebGalleryView.clear_folder"), //$NON-NLS-1$
                            IDialogConstants.CANCEL_LABEL },
                    0);
            switch (dialog.open()) {
            case 2:
                return true;
            case 1:
                Core.deleteFolderExcluding(file, "themes"); //$NON-NLS-1$
                break;
            }
        }
        String page = show.getPageName();
        final boolean ftp = isFtp;
        final File start = new File(file, (page == null || page.isEmpty()) ? "index.html" //$NON-NLS-1$
                : page);
        final WebGalleryImpl gal = show;
        final WebGalleryJob job = new WebGalleryJob(gal, generator, WebGalleryView.this);
        final FtpAccount account;
        if (ftp) {
            account = FtpAccount.findAccount(outputFolder);
            if (account == null) {
                AcousticMessageDialog.openError(getSite().getShell(),
                        Messages.getString("WebGalleryView.account_does_not_exist"), //$NON-NLS-1$
                        NLS.bind(Messages.getString("WebGalleryView.ftp_account_not_defined"), //$NON-NLS-1$
                                outputFolder));
                return true;
            }
        } else
            account = null;
        job.addJobChangeListener(new JobChangeAdapter() {
            @Override
            public void done(IJobChangeEvent event) {
                if (!job.wasAborted()) {
                    if (ftp)
                        new TransferJob(generator.getTargetFolder().listFiles(), account, true).schedule(0);
                    else
                        showWebGallery(save, start, gal);
                }
            }
        });
        job.schedule();
    } catch (CoreException e) {
        UiActivator.getDefault()
                .logError(NLS.bind(Messages.getString("WebGalleryView.error_when_instantiating_web_generator"), //$NON-NLS-1$
                        el.getAttribute("name")), e); //$NON-NLS-1$
    }
    return false;
}