Search in sources :

Example 11 with Messages

use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.

the class InternalSampler method saveSnapshot.

@Override
@Messages("SelfSamplerAction_SavedFile=Snapshot was saved to {0}")
protected void saveSnapshot(byte[] arr) throws IOException {
    // save snapshot
    File outFile = File.createTempFile(SAMPLER_NAME, SamplesOutputStream.FILE_EXT);
    File userDir = Places.getUserDirectory();
    File gestures = null;
    SelfSampleVFS fs;
    outFile = FileUtil.normalizeFile(outFile);
    writeToFile(outFile, arr);
    if (userDir != null) {
        // NOI18N
        gestures = new File(new File(new File(userDir, "var"), "log"), "uigestures");
    }
    if (gestures != null && gestures.exists()) {
        // NOI18N
        fs = new SelfSampleVFS(new String[] { FILE_NAME, SAMPLER_NAME + ".log" }, new File[] { outFile, gestures });
    } else {
        fs = new SelfSampleVFS(new String[] { FILE_NAME }, new File[] { outFile });
    }
    // open snapshot
    FileObject fo = fs.findResource(FILE_NAME);
    // test for DefaultDataObject
    if (UNKNOW_MIME_TYPE.equals(fo.getMIMEType())) {
        String msg = SelfSamplerAction_SavedFile(outFile.getAbsolutePath());
        DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg));
    } else {
        DataObject dobj = DataObject.find(fo);
        dobj.getLookup().lookup(Openable.class).open();
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File) Openable(org.netbeans.api.actions.Openable) Messages(org.openide.util.NbBundle.Messages)

Example 12 with Messages

use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.

the class TemplatesPanel method doNewFolder.

@Messages("TXT_TemplatesPanel_NewFolderName=New Folder")
private static DataFolder doNewFolder(Node[] nodes) {
    DataFolder df = null;
    // new folder
    DataFolder pref = getTargetFolder(nodes);
    if (pref == null) {
        pref = DataFolder.findFolder(getTemplatesRoot());
        assert pref != null : "DataFolder found for FO " + getTemplatesRoot();
    }
    // #161963: Create new DataFolder if DataFolder with given name already exists
    String baseName = TXT_TemplatesPanel_NewFolderName();
    String name = baseName;
    DataObject[] arr = pref.getChildren();
    boolean exists = true;
    int counter = 0;
    while (exists) {
        exists = false;
        for (int i = 0; i < arr.length; i++) {
            if (name.equals(arr[i].getName())) {
                counter++;
                name = baseName + " " + counter;
                exists = true;
                break;
            }
        }
    }
    try {
        df = DataFolder.create(pref, name);
        assert df != null : "New subfolder found in folder " + pref;
    } catch (IOException ioe) {
        Logger.getLogger(TemplatesPanel.class.getName()).log(Level.WARNING, null, ioe);
    }
    return df;
}
Also used : DataObject(org.openide.loaders.DataObject) IOException(java.io.IOException) DataFolder(org.openide.loaders.DataFolder) Messages(org.openide.util.NbBundle.Messages)

Example 13 with Messages

use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.

the class TemplatesPanel method showRename.

@Messages("RenameTemplatePanel.title.text=Rename Template")
private static void showRename(TemplateNode n) {
    String name = n.getFileName();
    String displayName = n.getDisplayName();
    FileObject fo = n.getLookup().lookup(FileObject.class);
    RenameTemplatePanel editPanel = new RenameTemplatePanel(isUserFile(fo));
    if (LICENSES_FOLDER.equals(fo.getParent().getPath())) {
        editPanel.setIsLicense(true);
    }
    editPanel.setOtherFileNames(getOtherFileNames(n));
    String title = RenameTemplatePanel_title_text();
    DialogDescriptor dd = new DialogDescriptor(editPanel, title);
    editPanel.setDescriptor(dd);
    editPanel.setFileName(name);
    editPanel.setFileDisplayName(displayName);
    Object res = DialogDisplayer.getDefault().notify(dd);
    if (DialogDescriptor.OK_OPTION.equals(res)) {
        name = editPanel.getFileName();
        displayName = editPanel.getFileDisplayName();
        n.setFileName(name);
        try {
            fo.setAttribute(TEMPLATE_DISPLAY_NAME_ATTRIBUTE, displayName);
            fo.setAttribute(TEMPLATE_LOCALIZING_BUNDLE_ATTRIBUTE, null);
        } catch (IOException ex) {
            Logger.getLogger(TemplatesPanel.class.getName()).log(Level.WARNING, null, ex);
        }
        n.setDisplayName(displayName);
    }
}
Also used : DialogDescriptor(org.openide.DialogDescriptor) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) FileObject(org.openide.filesystems.FileObject) IOException(java.io.IOException) Messages(org.openide.util.NbBundle.Messages)

Example 14 with Messages

use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.

the class TemplatesPanel method doAdd.

@Messages({ "LBL_TemplatesPanel_JFileChooser_Title=Add Existing Template", "BTN_TemplatesPanel_JFileChooser_AddButtonName=Add", "# {0} - file name", "MSG_TemplatesPanel_Nonexistent_File=File ''{0}''\ndoes not exist, please specify an existing file." })
private static void doAdd(final Node[] nodes) {
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogTitle(LBL_TemplatesPanel_JFileChooser_Title());
    chooser.setApproveButtonText(BTN_TemplatesPanel_JFileChooser_AddButtonName());
    chooser.setFileHidingEnabled(false);
    chooser.setMultiSelectionEnabled(false);
    int result = chooser.showOpenDialog(null);
    if (JFileChooser.APPROVE_OPTION == result) {
        final File f = chooser.getSelectedFile();
        assert f != null;
        if (!f.isFile()) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(MSG_TemplatesPanel_Nonexistent_File(f));
            DialogDisplayer.getDefault().notify(msg);
        } else {
            rp.post(new Runnable() {

                @Override
                public void run() {
                    DataObject template = createTemplateFromFile(f, getTargetFolder(nodes));
                    final Node node = getTemplateNode(template.getPrimaryFile());
                    if (node != null) {
                        try {
                            manager.setSelectedNodes(new Node[] { node });
                        } catch (PropertyVetoException ex) {
                        }
                    }
                }
            });
        }
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) PropertyVetoException(java.beans.PropertyVetoException) DataObject(org.openide.loaders.DataObject) JFileChooser(javax.swing.JFileChooser) Node(org.openide.nodes.Node) FilterNode(org.openide.nodes.FilterNode) File(java.io.File) Messages(org.openide.util.NbBundle.Messages)

Aggregations

Messages (org.openide.util.NbBundle.Messages)14 IOException (java.io.IOException)6 File (java.io.File)5 DataObject (org.openide.loaders.DataObject)5 FileObject (org.openide.filesystems.FileObject)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotifyDescriptor (org.openide.NotifyDescriptor)2 Node (org.openide.nodes.Node)2 PropertyVetoException (java.beans.PropertyVetoException)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParseException (java.text.ParseException)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1 Level (java.util.logging.Level)1 LogRecord (java.util.logging.LogRecord)1