Search in sources :

Example 1 with Messages

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

the class FileObj method getOutputStream.

@Messages("EXC_INVALID_FILE=File {0} is not valid")
public OutputStream getOutputStream(final FileLock lock, ProvidedExtensions extensions, FileObject mfo) throws IOException {
    if (LOGGER.isLoggable(Level.FINE) && EventQueue.isDispatchThread()) {
        LOGGER.log(Level.WARNING, "writing " + this, new IllegalStateException("getOutputStream invoked in AWT"));
    }
    final File f = getFileName().getFile();
    if (!isValid()) {
        FileObject recreated = this.getFileSystem().findResource(getPath());
        if (recreated instanceof FileObj && recreated != this) {
            return ((FileObj) recreated).getOutputStream(lock, extensions, mfo);
        }
        // NOI18N
        FileNotFoundException fnf = new FileNotFoundException("FileObject " + this + " is not valid; isFile=" + f.isFile());
        Exceptions.attachLocalizedMessage(fnf, Bundle.EXC_INVALID_FILE(this));
        throw fnf;
    }
    if (!BaseUtilities.isWindows() && !f.isFile()) {
        throw new IOException(f.getAbsolutePath());
    }
    final MutualExclusionSupport<FileObj>.Closeable closable = MUT_EXCL_SUPPORT.addResource(this, false);
    if (extensions != null) {
        extensions.beforeChange(mfo);
    }
    OutputStream retVal = null;
    try {
        final OutputStream delegate = Files.newOutputStream(f.toPath());
        retVal = new OutputStream() {

            @Override
            public void write(int b) throws IOException {
                delegate.write(b);
            }

            @Override
            public void close() throws IOException {
                if (!closable.isClosed()) {
                    delegate.close();
                    LOGGER.log(Level.FINEST, "getOutputStream-close");
                    Long lastModif = MOVED_FILE_TIMESTAMP.get();
                    if (lastModif != null) {
                        f.setLastModified(lastModif);
                    }
                    setLastModified(f, false);
                    closable.close();
                    fireFileChangedEvent(false);
                }
            }

            @Override
            public void flush() throws IOException {
                delegate.flush();
            }

            @Override
            public void write(byte[] b, int off, int len) throws IOException {
                delegate.write(b, off, len);
            }

            @Override
            public void write(byte[] b) throws IOException {
                delegate.write(b);
            }
        };
    } catch (FileNotFoundException e) {
        if (closable != null) {
            closable.close();
        }
        FileNotFoundException fex = e;
        if (!FileChangedManager.getInstance().exists(f)) {
            fex = (FileNotFoundException) new FileNotFoundException(e.getLocalizedMessage()).initCause(e);
        } else if (!f.canWrite()) {
            fex = (FileNotFoundException) new FileNotFoundException(e.getLocalizedMessage()).initCause(e);
        } else if (f.getParentFile() == null) {
            fex = (FileNotFoundException) new FileNotFoundException(e.getLocalizedMessage()).initCause(e);
        } else if (!FileChangedManager.getInstance().exists(f.getParentFile())) {
            fex = (FileNotFoundException) new FileNotFoundException(e.getLocalizedMessage()).initCause(e);
        }
        FSException.annotateException(fex);
        throw fex;
    }
    return retVal;
}
Also used : OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileObject(org.openide.filesystems.FileObject) File(java.io.File) Messages(org.openide.util.NbBundle.Messages)

Example 2 with Messages

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

the class InstallStep method notifyWritePermissionProblem.

@Messages({ "# {0} - plugin_name", "inBackground_WritePermission=You don''t have permission to install plugin {0} into the installation directory.", "inBackground_WritePermission_Details=details", "cancel=Cancel", "install=Install anyway" })
private void notifyWritePermissionProblem(final OperationException ex, final UpdateElement culprit) {
    // lack of privileges for writing
    ActionListener onMouseClickAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ProblemPanel problem = new ProblemPanel(ex, culprit, false);
            problem.showWriteProblemDialog();
        }
    };
    String title = inBackground_WritePermission(culprit.getDisplayName());
    String description = inBackground_WritePermission_Details();
    NotificationDisplayer.getDefault().notify(title, // NOI18N
    ImageUtilities.loadImageIcon("org/netbeans/modules/autoupdate/ui/resources/error.png", false), description, onMouseClickAction, NotificationDisplayer.Priority.HIGH, NotificationDisplayer.Category.ERROR);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ProblemPanel(org.netbeans.modules.autoupdate.ui.ProblemPanel) Messages(org.openide.util.NbBundle.Messages)

Example 3 with Messages

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

the class TemplatesPanel method createTemplateProperties.

@Messages({ "TemplatesPanel_TemplateNode_DisplayName=Display Name", "TemplatesPanel_TemplateNode_DisplayName_Desc=Display name of this template. Shown in File|New wizard as well as in Tools|Templates.", "TemplatesPanel_TemplateNode_FileName=File Name", "TemplatesPanel_TemplateNode_FileName_Desc=File name of file represented by this template.", "TemplatesPanel_TemplateNode_License=License URL(s)", "TemplatesPanel_TemplateNode_License_Desc=Authoritative web location of this license (may include several separated by spaces).", "TemplatesPanel_TemplateNode_ScriptEngine=Script Engine", "TemplatesPanel_TemplateNode_ScriptEngine_Desc=Script engine use for processing this template.", "TemplatesPanel_TemplateNode_TemplateCategories=Template Categories", "TemplatesPanel_TemplateNode_TemplateCategories_Desc=A list of template's categories appropriate for this template." })
private static Sheet.Set createTemplateProperties(final TemplateNode templateNode) {
    Sheet.Set properties = Sheet.createPropertiesSet();
    // display name
    properties.put(new PropertySupport.ReadWrite<String>(DataObject.PROP_NAME, String.class, TemplatesPanel_TemplateNode_DisplayName(), TemplatesPanel_TemplateNode_DisplayName_Desc()) {

        @Override
        public String getValue() throws IllegalAccessException, InvocationTargetException {
            return templateNode.getDisplayName();
        }

        @Override
        public void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
            templateNode.setName(val);
        }
    });
    // name == primary file filename
    properties.put(new PropertySupport.ReadWrite<String>(DataObject.PROP_PRIMARY_FILE, String.class, TemplatesPanel_TemplateNode_FileName(), TemplatesPanel_TemplateNode_FileName_Desc()) {

        @Override
        public String getValue() throws IllegalAccessException, InvocationTargetException {
            return templateNode.getFileName();
        }

        @Override
        public void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
            templateNode.setFileName(val);
        }
    });
    if (getDOFromNode(templateNode).getPrimaryFile().getPath().startsWith(LICENSES_FOLDER + "/")) {
        properties.put(new PropertySupport.ReadWrite<String>(TEMPLATE_LICENSE_URL_ATTRIBUTE, String.class, TemplatesPanel_TemplateNode_License(), TemplatesPanel_TemplateNode_License_Desc()) {

            @Override
            public String getValue() {
                Object o = getDOFromNode(templateNode).getPrimaryFile().getAttribute(TEMPLATE_LICENSE_URL_ATTRIBUTE);
                return o == null ? "" : o.toString();
            }

            @Override
            public void setValue(String v) throws InvocationTargetException {
                try {
                    getDOFromNode(templateNode).getPrimaryFile().setAttribute(TEMPLATE_LICENSE_URL_ATTRIBUTE, v.isEmpty() ? null : v);
                } catch (IOException x) {
                    throw new InvocationTargetException(x);
                }
            }
        });
    } else {
        // ScriptEngine
        properties.put(new PropertySupport.ReadWrite<String>(TEMPLATE_SCRIPT_ENGINE_ATTRIBUTE, String.class, TemplatesPanel_TemplateNode_ScriptEngine(), TemplatesPanel_TemplateNode_ScriptEngine_Desc()) {

            @Override
            public String getValue() throws IllegalAccessException, InvocationTargetException {
                DataObject dobj = getDOFromNode(templateNode);
                Object o = dobj.getPrimaryFile().getAttribute(TEMPLATE_SCRIPT_ENGINE_ATTRIBUTE);
                return o == null ? "" : o.toString();
            }

            @Override
            public void setValue(String val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                DataObject dobj = getDOFromNode(templateNode);
                try {
                    dobj.getPrimaryFile().setAttribute(TEMPLATE_SCRIPT_ENGINE_ATTRIBUTE, val);
                } catch (IOException ex) {
                    Logger.getLogger(TemplatesPanel.class.getName()).log(Level.INFO, ex.getLocalizedMessage(), ex);
                }
            }
        });
        properties.put(new PropertySupport.ReadWrite<String[]>(TEMPLATE_CATEGORY_ATTRIBUTE, String[].class, TemplatesPanel_TemplateNode_TemplateCategories(), TemplatesPanel_TemplateNode_TemplateCategories_Desc()) {

            @Override
            public String[] getValue() throws IllegalAccessException, InvocationTargetException {
                DataObject dobj = getDOFromNode(templateNode);
                Object o = dobj.getPrimaryFile().getAttribute(TEMPLATE_CATEGORY_ATTRIBUTE);
                if (o != null) {
                    List<String> list = new ArrayList<>();
                    // NOI18N
                    StringTokenizer tokenizer = new StringTokenizer(o.toString(), ",");
                    while (tokenizer.hasMoreTokens()) {
                        String token = tokenizer.nextToken();
                        list.add(token.trim());
                    }
                    return list.toArray(new String[0]);
                } else {
                    return null;
                }
            }

            @Override
            public void setValue(String[] val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
                DataObject dobj = getDOFromNode(templateNode);
                try {
                    if (val == null) {
                        dobj.getPrimaryFile().setAttribute(TEMPLATE_CATEGORY_ATTRIBUTE, null);
                    } else {
                        String list = Arrays.asList(val).toString();
                        list = list.substring(1, list.length() - 1);
                        dobj.getPrimaryFile().setAttribute(TEMPLATE_CATEGORY_ATTRIBUTE, list);
                    }
                } catch (IOException ex) {
                    Logger.getLogger(TemplatesPanel.class.getName()).log(Level.INFO, ex.getLocalizedMessage(), ex);
                }
            }
        });
    }
    return properties;
}
Also used : IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringTokenizer(java.util.StringTokenizer) DataObject(org.openide.loaders.DataObject) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) List(java.util.List) ArrayList(java.util.ArrayList) Sheet(org.openide.nodes.Sheet) PropertySupport(org.openide.nodes.PropertySupport) Messages(org.openide.util.NbBundle.Messages)

Example 4 with Messages

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

the class LogAction method actionPerformed.

@Messages("MSG_ShortLogTab_name=IDE Log")
@Override
public void actionPerformed(ActionEvent evt) {
    File userDir = Places.getUserDirectory();
    if (userDir == null) {
        return;
    }
    File f = new File(userDir, "/var/log/messages.log");
    LogViewerSupport p = new LogViewerSupport(f, MSG_ShortLogTab_name());
    try {
        p.showLogViewer();
    } catch (IOException e) {
        Logger.getLogger(LogAction.class.getName()).log(Level.INFO, "Showing IDE log action failed", e);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) Messages(org.openide.util.NbBundle.Messages)

Example 5 with Messages

use of org.openide.util.NbBundle.Messages in project JJazzLab-X by jjazzboss.

the class Position method valueOf.

/**
 * Set the position from a string as the one returned by toString() eg "[2:3.5]" or "[3]"
 * <p>
 * Ex: "[2:3.5]" will set bar=2 and beat=3.5<br>
 * Ex: "[3.5]" set bar=defaultBar and beat=3.5
 *
 * @param userString The string as returned by toString()
 * @param defaultBar If bar is not specified, defaultBar is used.
 *
 * @throws ParseException If syntax error in string.
 */
@Messages({ "CTL_InvalidValue=Invalid position string", "CTL_MissingEnclosingChars=Missing enclosing chars", "CTL_NegativeValue=Negative value not allowed" })
public void valueOf(String userString, int defaultBar) throws ParseException {
    int newBar = bar;
    float newBeat = beat;
    if ((userString == null) || (defaultBar < 0)) {
        // NOI18N
        throw new IllegalArgumentException("str=" + userString + " defaultBar=" + defaultBar);
    }
    // Remove brackets
    String s1 = userString.trim();
    if (s1.indexOf(START_CHAR) != 0 || s1.indexOf(END_CHAR) != s1.length() - 1) {
        throw new ParseException(userString + " : " + CTL_MissingEnclosingChars() + " " + START_CHAR + END_CHAR, 0);
    }
    String s = s1.substring(1, s1.length() - 1);
    int indSep = s.indexOf(SEPARATOR_CHAR);
    if (indSep == -1) {
        // No newBar specified so use default newBar
        newBar = defaultBar + 1;
        String strBeat = s.replace(',', '.');
        try {
            newBeat = Float.parseFloat(strBeat);
        } catch (NumberFormatException e) {
            throw new ParseException(userString + " : " + CTL_InvalidValue() + " " + e.getLocalizedMessage(), 0);
        }
        if (newBeat < 0) {
            throw new ParseException(userString + " : " + CTL_NegativeValue(), 0);
        }
    } else {
        // Bar and newBeat specified
        try {
            newBar = Integer.parseInt(s.substring(0, indSep));
        } catch (NumberFormatException e) {
            throw new ParseException(userString + " : " + CTL_InvalidValue() + " " + e.getLocalizedMessage(), 0);
        }
        if (newBar < 0) {
            throw new ParseException(userString + " : " + CTL_NegativeValue(), 0);
        }
        String strBeat = s.substring(indSep + 1).replace(',', '.');
        try {
            newBeat = Float.parseFloat(strBeat);
        } catch (NumberFormatException e) {
            throw new ParseException(userString + " : " + CTL_InvalidValue() + " " + e.getLocalizedMessage(), indSep + 1);
        }
        if (newBeat < 0) {
            throw new ParseException(userString + " : " + CTL_NegativeValue(), indSep + 1);
        }
    }
    setBar(newBar);
    setBeat(newBeat);
}
Also used : ParseException(java.text.ParseException) 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