Java Code Examples for org.openide.NotifyDescriptor#ERROR_MESSAGE

The following examples show how to use org.openide.NotifyDescriptor#ERROR_MESSAGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MacroDialogSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void error(JTextComponent target, String messageKey, Object... params) {
    String message;
    try {
        message = NbBundle.getMessage(RunMacroAction.class, messageKey, params);
    } catch (MissingResourceException e) {
        message = "Error in macro: " + messageKey; //NOI18N
    }
    
    NotifyDescriptor descriptor = new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE); // NOI18N

    Toolkit.getDefaultToolkit().beep();
    DialogDisplayer.getDefault().notify(descriptor);
    if (LOG.isLoggable(Level.FINE)) {
        LOG.log(Level.FINE, null, new Throwable(message));
    }
}
 
Example 2
Source File: QueryBuilder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Return the java.sql.Connection associated with this dbconn, after opening 
 * it if necessary.
 */
Connection getConnection() {

    Connection conn = dbconn.getJDBCConnection();
    if (conn== null) {
        // Try to (re-) open the connection
        ConnectionManager.getDefault().showConnectionDialog(dbconn);
        conn = dbconn.getJDBCConnection();
        if (conn==null) {
            // Connection failed for some reason.  User may have cancelled.
            // If there's an exception, ConnectionDialog already reported it.
            String msg = NbBundle.getMessage(QueryBuilder.class, "CANNOT_ESTABLISH_CONNECTION");     // NOI18N
            NotifyDescriptor d =
                new NotifyDescriptor.Message(msg + "\n\n", NotifyDescriptor.ERROR_MESSAGE); // NOI18N
            DialogDisplayer.getDefault().notify(d);
        }
    }
    return conn;
}
 
Example 3
Source File: InternalVSEMetaDataImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private DatabaseMetaData getMetaData() throws SQLException {
    if (databaseMetaData == null) {            
        Connection conn = dbconn.getJDBCConnection();
        if (conn == null) {                
            String msg = NbBundle.getMessage(QueryBuilder.class, "CANNOT_ESTABLISH_CONNECTION");     // NOI18N
            NotifyDescriptor d =
                new NotifyDescriptor.Message(msg + "\n\n", NotifyDescriptor.ERROR_MESSAGE); // NOI18N
            DialogDisplayer.getDefault().notify(d);                
        } else {
            databaseMetaData = dbconn.getJDBCConnection().getMetaData();
        }
    }
    return databaseMetaData;
}
 
Example 4
Source File: DefaultPlugin.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Messages({"# {0} - template file","MSG_template_not_found=Template file {0} was not found. Check the TestNG templates in the Template manager."})
private static void noTemplateMessage(String temp) {
    String msg = Bundle.MSG_template_not_found(temp);     //NOI18N
    NotifyDescriptor descr = new NotifyDescriptor.Message(
            msg,
            NotifyDescriptor.ERROR_MESSAGE);
    DialogDisplayer.getDefault().notify(descr);
}
 
Example 5
Source File: PropertiesDataNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Overrides superclass method. */
@Override
public void create() throws IOException {
    final PropertiesDataObject propertiesDataObject =
                      (PropertiesDataObject)getCookie(DataObject.class);

    final Dialog[] dialog = new Dialog[1];
    final LocalePanel panel = new LocalePanel();

    DialogDescriptor dialogDescriptor = new DialogDescriptor(
        panel,
        NbBundle.getBundle(PropertiesDataNode.class).getString("CTL_NewLocaleTitle"),
        true,
        DialogDescriptor.OK_CANCEL_OPTION,
        DialogDescriptor.OK_OPTION,
        new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                if (evt.getSource() == DialogDescriptor.OK_OPTION) {
                    if (containsLocale(propertiesDataObject, panel.getLocale())) {
                        NotifyDescriptor.Message msg = new NotifyDescriptor.Message(
                            MessageFormat.format(NbBundle.getBundle(PropertiesDataNode.class).getString("MSG_LangExists"), panel.getLocale()), 
                            NotifyDescriptor.ERROR_MESSAGE);
                        DialogDisplayer.getDefault().notify(msg);
                    } else {
                        Util.createLocaleFile(propertiesDataObject, panel.getLocale().toString(), true);
                        dialog[0].setVisible(false);
                        dialog[0].dispose();
                    }
                }
            }
        }
    );
    dialogDescriptor.setClosingOptions(new Object [] { DialogDescriptor.CANCEL_OPTION });
    
    dialog[0] = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
    dialog[0].setVisible(true);
}
 
Example 6
Source File: JaxWsServiceCreator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void createServiceFromWsdl() throws IOException {

        //initProjectInfo(project);

        final ProgressHandle handle = ProgressHandleFactory.createHandle(
                NbBundle.getMessage(JaxWsServiceCreator.class, 
                        "TXT_WebServiceGeneration")); //NOI18N

        Runnable r = new Runnable() {

            public void run() {
                try {
                    handle.start();
                    generateWsFromWsdl15(handle);
                } catch (Exception e) {
                    //finish progress bar
                    handle.finish();
                    String message = e.getLocalizedMessage();
                    if (message != null) {
                        ErrorManager.getDefault().notify(
                                ErrorManager.INFORMATIONAL, e);
                        NotifyDescriptor nd = new NotifyDescriptor.Message(
                                message, NotifyDescriptor.ERROR_MESSAGE);
                        DialogDisplayer.getDefault().notify(nd);
                    } else {
                        ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
                    }
                }
            }
        };
        RequestProcessor.getDefault().post(r);
    }
 
Example 7
Source File: SaveAsAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    Node node = activatedNodes[0];
    FileObject fo = node.getLookup().lookup(FileObject.class);
    if (fo != null) {
        FileChooserBuilder builder = new FileChooserBuilder(SaveAsAction.class);
        builder.setDirectoriesOnly(false);
        builder.setApproveText("Save");
        builder.setControlButtonsAreShown(true);
        builder.setTitle("Save As...");
        builder.setFilesOnly(true);
        builder.setFileFilter(new FileNameExtensionFilter(fo.getExt(), fo.getExt()));
        JFileChooser chooser = builder.createFileChooser();
        chooser.setSelectedFile(new File(fo.getNameExt()));
        int resp = chooser.showSaveDialog(findDialogParent());
        if (JFileChooser.APPROVE_OPTION == resp) {
            File saveFile = chooser.getSelectedFile();
            if (saveFile != null) {
                try {
                    saveFile.getParentFile().mkdirs();
                    FileObject dfo = FileUtil.toFileObject(saveFile.getParentFile());
                    if (dfo == null) {
                        NotifyDescriptor nd = new NotifyDescriptor.Message("Unable to Save file!", NotifyDescriptor.ERROR_MESSAGE);
                        DialogDisplayer.getDefault().notifyLater(nd);
                        return;
                    }
                    if (saveFile.exists()) {
                        saveFile.delete();
                    }
                    fo.copy(dfo, saveFile.getName(), "");
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}
 
Example 8
Source File: AppClientProjectWebServicesClientSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setWsdlSource(String serviceName, String wsdlSource) {
    Element data = helper.getPrimaryConfigurationData(true);
    Document doc = data.getOwnerDocument();
    boolean needsSave = false;
    
    Element clientElement = getWebServiceClientNode(data, serviceName);
    if(clientElement != null) {
        NodeList fromWsdlList = clientElement.getElementsByTagNameNS(
        AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL);
        if(fromWsdlList.getLength() > 0) {
            Element fromWsdlElement = (Element) fromWsdlList.item(0);
            NodeList nl = fromWsdlElement.getChildNodes();
            if(nl.getLength() > 0) {
                Node n = nl.item(0);
                n.setNodeValue(wsdlSource);
            } else {
                fromWsdlElement.appendChild(doc.createTextNode(wsdlSource));
            }
        } else {
            Element clientElementSourceUrl = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL);
            clientElement.appendChild(clientElementSourceUrl);
            clientElementSourceUrl.appendChild(doc.createTextNode(wsdlSource));
        }
        
        needsSave = true;
    }
    
    // !PW Save the project if we were able to make the change.
    if(needsSave) {
        try {
            ProjectManager.getDefault().saveProject(project);
        } catch(IOException ex) {
            NotifyDescriptor desc = new NotifyDescriptor.Message(
            NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), // NOI18N
            NotifyDescriptor.ERROR_MESSAGE);
            DialogDisplayer.getDefault().notify(desc);
        }
    }
}
 
Example 9
Source File: OpenSceneComposer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void actionPerformed(ActionEvent ev) {
    final ProjectAssetManager manager = context.getLookup().lookup(ProjectAssetManager.class);
    if (manager == null) {
        return;
    }
    Runnable call = new Runnable() {

        public void run() {
            ProgressHandle progressHandle = ProgressHandleFactory.createHandle("Opening in SceneComposer");
            progressHandle.start();
            try {

                final Spatial asset = context.loadAsset();

                if (asset != null) {
                    java.awt.EventQueue.invokeLater(new Runnable() {

                        public void run() {
                            manager.clearCache();
                            SceneComposerTopComponent composer = SceneComposerTopComponent.findInstance();
                            composer.openScene(asset, context, manager);
                        }
                    });
                } else {
                    Confirmation msg = new NotifyDescriptor.Confirmation(
                            "Error opening " + context.getPrimaryFile().getNameExt(),
                            NotifyDescriptor.OK_CANCEL_OPTION,
                            NotifyDescriptor.ERROR_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
            } finally {
                progressHandle.finish();
            }
        }
    };
    new Thread(call).start();
}
 
Example 10
Source File: CustomFilter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static ScriptEngineAbstraction getEngine() {
    if (engine == null) {

        ScriptEngineAbstraction chosen = null;
        try {
            Collection<? extends ScriptEngineAbstraction> list = Lookup.getDefault().lookupAll(ScriptEngineAbstraction.class);
            for (ScriptEngineAbstraction s : list) {
                if (s.initialize(getJsHelperText())) {
                    if (chosen == null || !(chosen instanceof JavaSE6ScriptEngine)) {
                        chosen = s;
                    }
                }
            }
        } catch (NoClassDefFoundError ncdfe) {
            Logger.getLogger("global").log(Level.SEVERE, null, ncdfe);
        }

        if (chosen == null) {
            NotifyDescriptor message = new NotifyDescriptor.Message("Could not find a scripting engine. Please make sure that the Rhino scripting engine is available. Otherwise filter cannot be used.", NotifyDescriptor.ERROR_MESSAGE);
            DialogDisplayer.getDefault().notifyLater(message);
            chosen = new NullScriptEngine();
        }

        engine = chosen;
    }

    return engine;
}
 
Example 11
Source File: JaxWsServiceCreator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void createServiceFromWsdl() throws IOException {

    //initProjectInfo(project);

    final ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(JaxWsServiceCreator.class, "TXT_WebServiceGeneration")); //NOI18N

    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                handle.start(100);
                generateWsFromWsdl15(handle);
            } catch (IOException e) {
                //finish progress bar
                handle.finish();
                String message = e.getLocalizedMessage();
                if (message != null) {
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
                    NotifyDescriptor nd = new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE);
                    DialogDisplayer.getDefault().notify(nd);
                } else {
                    ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
                }
            }
        }
    };
    RequestProcessor.getDefault().post(r);
}
 
Example 12
Source File: CreateSampleDBAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void performAction() {
    if (!Util.checkInstallLocation()) {
        return;
    }
    if (!Util.ensureSystemHome()) {
        return;
    }
    
    String derbySystemHome = DerbyOptions.getDefault().getSystemHome();
    CreateSampleDatabasePanel panel = new CreateSampleDatabasePanel(derbySystemHome);
    DialogDescriptor desc = new DialogDescriptor(panel, NbBundle.getMessage(CreateSampleDBAction.class, "LBL_CreateSampleDatabaseTitle"), true, null);
    desc.createNotificationLineSupport();
    panel.setDialogDescriptor(desc);
    Dialog dialog = DialogDisplayer.getDefault().createDialog(desc);
    panel.setIntroduction();
    String acsd = NbBundle.getMessage(CreateSampleDBAction.class, "ACSD_CreateDatabaseAction");
    dialog.getAccessibleContext().setAccessibleDescription(acsd);
    dialog.setVisible(true);
    dialog.dispose();
    
    if (!DialogDescriptor.OK_OPTION.equals(desc.getValue())) {
        return;
    }
    
    String databaseName = panel.getDatabaseName();
    
    try {
        DerbyDatabasesImpl.getDefault().createSampleDatabase(databaseName, true);
    } catch (Exception e) {
        LOG.log(Level.INFO, null, e);
        LOG.log(Level.INFO, "", e);
        NotifyDescriptor nd = new NotifyDescriptor.Message(
                "Failed to ceate sample database:\n"
                + e.getLocalizedMessage(),
                NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notifyLater(nd);
    }
}
 
Example 13
Source File: OpenEgtaskFile.java    From BART with MIT License 4 votes vote down vote up
private NotifyDescriptor myNotify(String message)   {
    return new NotifyDescriptor(message, 
         "Wrog File", 
          NotifyDescriptor.DEFAULT_OPTION, 
          NotifyDescriptor.ERROR_MESSAGE, new Object[]{NotifyDescriptor.CLOSED_OPTION}, null);
}
 
Example 14
Source File: NodeJsPathPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void informUser(String message) {
    NotifyDescriptor descriptor = new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE);
    DialogDisplayer.getDefault().notifyLater(descriptor);
}
 
Example 15
Source File: WsImportFailedMessage.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public WsImportFailedMessage(boolean isService, Throwable ex) {
    super(NbBundle.getMessage(WsImportFailedMessage.class, (isService? "TXT_CannotGenerateService" : "TXT_CannotGenerateClient"), ex.getLocalizedMessage()),
            NotifyDescriptor.ERROR_MESSAGE);
}
 
Example 16
Source File: JaxWsUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public WsImportServiceFailedMessage(Throwable ex) {
    super(NbBundle.getMessage(JaxWsUtils.class, "TXT_CannotGenerateService",    // NOI18N 
            ex.getLocalizedMessage()),NotifyDescriptor.ERROR_MESSAGE);
}
 
Example 17
Source File: OWSMPoliciesEditor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void doSave(){
    if ( myPanel == null ){
        return;
    }
    if ( myPanel.getWsFqn() == null ){
        return;
    }
    final JavaSource javaSource = JavaSource.forFileObject(myFileObject );
    if ( javaSource == null ) {
        NotifyDescriptor descriptor = new NotifyDescriptor.Message( 
                NbBundle.getMessage(OWSMPoliciesEditor.class, "ERR_NoJava"),    // NOI18N
                NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify( descriptor );
        return;
    }
    final List<String> policyIds = myPanel.getPolicyIds();
    List<String> fqns = new ArrayList<String>(2);
    fqns.add( PoliciesVisualPanel.OWSM_SECURITY_POLICY);
    if ( policyIds.size() >1 ){
        fqns.add(PoliciesVisualPanel.OWSM_SECURITY_POLICIES);
    }
    Project project = FileOwnerQuery.getOwner(myFileObject);
    mySupport.extendsProjectClasspath(project, fqns);
    final Task<WorkingCopy> task = new Task<WorkingCopy>() {

        @Override
        public void run( WorkingCopy workingCopy ) throws Exception {
            workingCopy.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
            String wsFqn = myPanel.getWsFqn();
            
            CompilationUnitTree cu = workingCopy.getCompilationUnit();
            ClassTree wsClassTree = null;
            if (cu != null) {
                List<? extends Tree> decls = cu.getTypeDecls();
                for (Tree decl : decls) {
                    if (!TreeUtilities.CLASS_TREE_KINDS.contains(decl
                            .getKind()))
                    {
                        continue;
                    }

                    ClassTree classTree = (ClassTree) decl;
                    Element element = workingCopy.getTrees()
                            .getElement(
                                    workingCopy.getTrees().getPath(cu,
                                            classTree));
                    if (element instanceof TypeElement) {
                        Name className = ((TypeElement) element)
                                .getQualifiedName();
                        if (className.contentEquals(wsFqn)) {
                            wsClassTree = classTree;
                        }
                    }
                }
            }
            if (wsClassTree == null) {
                return;
            }
            rewriteAnnotations(policyIds, workingCopy, wsClassTree);
        }

    };
    final Runnable runnable = new Runnable() {
        
        @Override
        public void run() {
            try {
                javaSource.runModificationTask(task).commit();
            }
            catch (IOException e) {
                Logger.getLogger( OWSMPoliciesEditor.class.getName() ).log( 
                        Level.INFO, null, e );
            }
        }
    };
    final String title = NbBundle.getMessage(OWSMPoliciesEditor.class, 
            "LBL_ModifyPolicies");                  // NOI18N
    if ( SwingUtilities.isEventDispatchThread() ){
        ScanDialog.runWhenScanFinished(runnable, title );
    }
    else {
        SwingUtilities.invokeLater( new Runnable() {
            
            @Override
            public void run() {
                ScanDialog.runWhenScanFinished(runnable, title );                        
            }
        });
    }
}
 
Example 18
Source File: RelatedCMPWizard.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Set<DataObject> instantiate(final TemplateWizard wiz) throws IOException {
    // create the pu first if needed
    if (helper.isCreatePU()) {
        Util.addPersistenceUnitToProjectRoot(project, helper.getLocation().getRootFolder(), Util.buildPersistenceUnitUsingData(project, getDefaultPersistenceUnitName(helper.getLocation().getRootFolder()), helper.getDatabaseConnection() != null ? helper.getTableSource().getName() : null, null, null));
    } else {
        Util.addPersistenceUnitToProject(project);
    }

    final String title = NbBundle.getMessage(RelatedCMPWizard.class, "TXT_EntityClassesGeneration");
    final ProgressContributor progressContributor = AggregateProgressFactory.createProgressContributor(title);
    final AggregateProgressHandle handle =
            AggregateProgressFactory.createHandle(title, new ProgressContributor[]{progressContributor}, null, null);
    progressPanel = new ProgressPanel();
    final JComponent progressComponent = AggregateProgressFactory.createProgressComponent(handle);

    final Runnable r = new Runnable() {
        @Override
        public void run() {
            try {
                handle.start();
                createBeans(wiz, progressContributor);
            } catch (IOException ioe) {
                Logger.getLogger("global").log(Level.INFO, null, ioe);
                NotifyDescriptor nd = new NotifyDescriptor.Message(ioe.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
                DialogDisplayer.getDefault().notify(nd);
            } finally {
                generator.uninit();
                handle.finish();
            }
        }
    };

    // Ugly hack ensuring the progress dialog opens after the wizard closes. Needed because:
    // 1) the wizard is not closed in the AWT event in which instantiate() is called.
    //    Instead it is closed in an event scheduled by SwingUtilities.invokeLater().
    // 2) when a modal dialog is created its owner is set to the foremost modal
    //    dialog already displayed (if any). Because of #1 the wizard will be
    //    closed when the progress dialog is already open, and since the wizard
    //    is the owner of the progress dialog, the progress dialog is closed too.
    // The order of the events in the event queue:
    // -  this event
    // -  the first invocation event of our runnable
    // -  the invocation event which closes the wizard
    // -  the second invocation event of our runnable


    SwingUtilities.invokeLater(new Runnable() {
        private boolean first = true;

        @Override
        public void run() {
            if (!first) {
                RP.post(r);
                progressPanel.open(progressComponent, title);
            } else {
                first = false;
                SwingUtilities.invokeLater(this);
            }
        }
    });

    // The commented code below is the ideal state, but since there is not way to request
    // TemplateWizard.Iterator.instantiate() be called asynchronously it
    // would cause the wizard to stay visible until the bean generation process
    // finishes. So for now just returning the package -- not a problem,
    // JavaPersistenceGenerator.createdObjects() returns an empty set anyway.

    // remember to wait for createBeans() to actually return!
    // Set created = generator.createdObjects();
    // if (created.size() == 0) {
    //     created = Collections.singleton(SourceGroupSupport.getFolderForPackage(helper.getLocation(), helper.getPackageName()));
    // }
    if (helper.isCreatePU() && helper.getDBSchemaFile() != null) {//for now open persistence.xml in case of schema was used, as it's 99% will require persistence.xml update
        DataObject dObj = null;
        try {
            dObj = ProviderUtil.getPUDataObject(project, helper.getLocation().getRootFolder(), null);
        } catch (InvalidPersistenceXmlException ex) {
        }
        if (dObj != null) {
            return Collections.<DataObject>singleton(dObj);
        }
    }

    return Collections.<DataObject>singleton(DataFolder.findFolder(
            SourceGroups.getFolderForPackage(helper.getLocation(), helper.getPackageName())));
}
 
Example 19
Source File: ParamEditor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
    * Handle user input...
    */

   public void evaluateInput() {

if (editDialog.getValue().equals(NotifyDescriptor.CANCEL_OPTION)) { 
    dialog.dispose();
    dialogOK = false; 
    return; 
}

if(editable == Editable.NEITHER) {
    dialog.dispose();
    dialogOK = false; 
    return;
}

errorMessage = null; 

if(name.equals("")) 
    errorMessage = NbBundle.getMessage(ParamEditor.class, 
				       "MSG_no_name"); 
else if(condition == Condition.COOKIE && name.equalsIgnoreCase("jsessionid"))
    errorMessage = NbBundle.getMessage(ParamEditor.class, 
				       "MSG_no_jsession"); 
else if(condition == Condition.VALUE && value.equals("")) 
    errorMessage = NbBundle.getMessage(ParamEditor.class, 
				       "MSG_no_value"); 
else if(condition == Condition.HEADER && 
	name.equalsIgnoreCase("cookie") &&
	(value.indexOf("jsessionid") > -1 ||
	 value.indexOf("JSESSIONID") > -1))
    errorMessage = NbBundle.getMessage(ParamEditor.class, 
				       "MSG_no_jsession"); 

if(errorMessage == null) { 
    dialog.dispose();
    dialogOK = true; 
} 
else {
   editDialog.setValue(NotifyDescriptor.CLOSED_OPTION);
   NotifyDescriptor nd = new NotifyDescriptor.Message
       (errorMessage, NotifyDescriptor.ERROR_MESSAGE); 
    DialogDisplayer.getDefault().notify(nd);
}
   }
 
Example 20
Source File: CustomizerSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void addPathElement () {
    JFileChooser chooser = new JFileChooser();
    FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
    chooser.setMultiSelectionEnabled (true);
    String title = null;
    String message = null;
    String approveButtonName = null;
    String approveButtonNameMne = null;
    if (SOURCES.equals(this.type)) {
        title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
        message = NbBundle.getMessage (CustomizerSupport.class,"TXT_Sources");
        approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenSources");
        approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenSources");
    } else if (JAVADOC.equals(this.type)) {
        title = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
        message = NbBundle.getMessage (CustomizerSupport.class,"TXT_Javadoc");
        approveButtonName = NbBundle.getMessage (CustomizerSupport.class,"TXT_OpenJavadoc");
        approveButtonNameMne = NbBundle.getMessage (CustomizerSupport.class,"MNE_OpenJavadoc");
    } else {
        throw new IllegalStateException("Can't add element for classpath"); // NOI18N
    }
    chooser.setDialogTitle(title);
    chooser.setApproveButtonText(approveButtonName);
    chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter (new SimpleFileFilter(message,new String[] {"ZIP","JAR"}));   //NOI18N
    if (this.currentDir != null && currentDir.exists()) {
        chooser.setCurrentDirectory(this.currentDir);
    }
    if (chooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
        File[] fs = chooser.getSelectedFiles();
        PathModel model = (PathModel) this.resources.getModel();
        boolean addingFailed = false;
        int firstIndex = this.resources.getModel().getSize();
        for (int i = 0; i < fs.length; i++) {
            File f = fs[i];
            //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
            // E.g. for /foo/src it returns /foo/src/src
            // Try to convert it back by removing last invalid name component
            if (!f.exists()) {
                File parent = f.getParentFile();
                if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
                    f = parent;
                }
            }
            addingFailed|=!model.addPath (f);
        }
        if (addingFailed) {
            new NotifyDescriptor.Message (NbBundle.getMessage(CustomizerSupport.class,"TXT_CanNotAddResolve"),
                    NotifyDescriptor.ERROR_MESSAGE);
        }
        int lastIndex = this.resources.getModel().getSize()-1;
        if (firstIndex<=lastIndex) {
            int[] toSelect = new int[lastIndex-firstIndex+1];
            for (int i = 0; i < toSelect.length; i++) {
                toSelect[i] = firstIndex+i;
            }
            this.resources.setSelectedIndices(toSelect);
        }
        this.currentDir = FileUtil.normalizeFile(chooser.getCurrentDirectory());
    }
}