Search in sources :

Example 1 with SaveAsCapable

use of org.openide.loaders.SaveAsCapable in project netbeans-rcp-lite by outersky.

the class SaveAsAction method actionPerformed.

public void actionPerformed(ActionEvent e) {
    refreshListeners();
    Collection<? extends SaveAsCapable> inst = lkpInfo.allInstances();
    if (inst.size() > 0) {
        SaveAsCapable saveAs = inst.iterator().next();
        File newFile = getNewFileName();
        if (null != newFile) {
            // create target folder if necessary
            FileObject newFolder = null;
            try {
                File targetFolder = newFile.getParentFile();
                if (null == targetFolder)
                    throw new IOException(newFile.getAbsolutePath());
                newFolder = FileUtil.createFolder(targetFolder);
            } catch (IOException ioE) {
                NotifyDescriptor error = new NotifyDescriptor(// NOI18N
                NbBundle.getMessage(DataObject.class, "MSG_CannotCreateTargetFolder"), // NOI18N
                NbBundle.getMessage(DataObject.class, "LBL_SaveAsTitle"), NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[] { NotifyDescriptor.OK_OPTION }, NotifyDescriptor.OK_OPTION);
                DialogDisplayer.getDefault().notify(error);
                return;
            }
            try {
                saveAs.saveAs(newFolder, newFile.getName());
            } catch (IOException ioE) {
                Exceptions.attachLocalizedMessage(ioE, // NOI18N
                NbBundle.getMessage(// NOI18N
                DataObject.class, // NOI18N
                "MSG_SaveAsFailed", newFile.getName(), ioE.getLocalizedMessage()));
                Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ioE);
            }
        }
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) SaveAsCapable(org.openide.loaders.SaveAsCapable) FileObject(org.openide.filesystems.FileObject) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) IOException(java.io.IOException) File(java.io.File)

Example 2 with SaveAsCapable

use of org.openide.loaders.SaveAsCapable in project constellation by constellation-app.

the class SaveAsAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    refreshListeners();
    final Collection<? extends SaveAsCapable> inst = lkpInfo.allInstances();
    if (!inst.isEmpty()) {
        final SaveAsCapable saveAs = inst.iterator().next();
        final File newFile = getNewFileName();
        if (newFile != null) {
            try {
                saveAs.saveAs(FileUtil.toFileObject(newFile.getParentFile()), newFile.getName());
                // take a screenshot in a separate thread in parrallel
                new Thread(() -> RecentGraphScreenshotUtilities.takeScreenshot(newFile.getName()), "Take Graph Screenshot").start();
            } catch (final IOException ioE) {
                Exceptions.attachLocalizedMessage(ioE, Bundle.MSG_SaveAsFailed(newFile.getName(), ioE.getLocalizedMessage()));
                LOGGER.log(Level.SEVERE, null, ioE);
            }
            isSaved = true;
        }
    }
}
Also used : SaveAsCapable(org.openide.loaders.SaveAsCapable) IOException(java.io.IOException) File(java.io.File)

Example 3 with SaveAsCapable

use of org.openide.loaders.SaveAsCapable in project constellation by constellation-app.

the class SaveAsAction method refreshEnabled.

private void refreshEnabled() {
    if (lkpInfo == null) {
        // The thing we want to listen for the presence or absence of
        // on the global selection
        Lookup.Template<SaveAsCapable> tpl = new Lookup.Template<>(SaveAsCapable.class);
        lkpInfo = context.lookup(tpl);
    }
    TopComponent tc = TopComponent.getRegistry().getActivated();
    boolean isEditorWindowActivated = tc != null && WindowManager.getDefault().isEditorTopComponent(tc);
    setEnabled(lkpInfo != null && !lkpInfo.allItems().isEmpty() && isEditorWindowActivated);
    isDirty = false;
}
Also used : SaveAsCapable(org.openide.loaders.SaveAsCapable) Lookup(org.openide.util.Lookup) TopComponent(org.openide.windows.TopComponent)

Example 4 with SaveAsCapable

use of org.openide.loaders.SaveAsCapable in project netbeans-rcp-lite by outersky.

the class SaveAsAction method refreshEnabled.

private void refreshEnabled() {
    if (lkpInfo == null) {
        // The thing we want to listen for the presence or absence of
        // on the global selection
        Lookup.Template<SaveAsCapable> tpl = new Lookup.Template<SaveAsCapable>(SaveAsCapable.class);
        lkpInfo = context.lookup(tpl);
    }
    TopComponent tc = TopComponent.getRegistry().getActivated();
    boolean isEditorWindowActivated = null != tc && WindowManager.getDefault().isEditorTopComponent(tc);
    setEnabled(null != lkpInfo && lkpInfo.allItems().size() != 0 && isEditorWindowActivated);
    isDirty = false;
}
Also used : SaveAsCapable(org.openide.loaders.SaveAsCapable) Lookup(org.openide.util.Lookup) TopComponent(org.openide.windows.TopComponent)

Aggregations

SaveAsCapable (org.openide.loaders.SaveAsCapable)4 File (java.io.File)2 IOException (java.io.IOException)2 Lookup (org.openide.util.Lookup)2 TopComponent (org.openide.windows.TopComponent)2 NotifyDescriptor (org.openide.NotifyDescriptor)1 FileObject (org.openide.filesystems.FileObject)1 DataObject (org.openide.loaders.DataObject)1