Search in sources :

Example 6 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project gephi by gephi.

the class ProjectControllerUIImpl method closeCurrentProject.

public boolean closeCurrentProject() {
    if (controller.getCurrentProject() != null) {
        //Save ?
        String messageBundle = NbBundle.getMessage(ProjectControllerUIImpl.class, "CloseProject_confirm_message");
        String titleBundle = NbBundle.getMessage(ProjectControllerUIImpl.class, "CloseProject_confirm_title");
        String saveBundle = NbBundle.getMessage(ProjectControllerUIImpl.class, "CloseProject_confirm_save");
        String doNotSaveBundle = NbBundle.getMessage(ProjectControllerUIImpl.class, "CloseProject_confirm_doNotSave");
        String cancelBundle = NbBundle.getMessage(ProjectControllerUIImpl.class, "CloseProject_confirm_cancel");
        NotifyDescriptor msg = new NotifyDescriptor(messageBundle, titleBundle, NotifyDescriptor.YES_NO_CANCEL_OPTION, NotifyDescriptor.INFORMATION_MESSAGE, new Object[] { saveBundle, doNotSaveBundle, cancelBundle }, saveBundle);
        Object result = DialogDisplayer.getDefault().notify(msg);
        if (result == saveBundle) {
            saveProject();
        } else if (result == cancelBundle) {
            return false;
        }
        controller.closeCurrentProject();
        //Actions
        saveProject = false;
        saveAsProject = false;
        projectProperties = false;
        closeProject = false;
        newWorkspace = false;
        deleteWorkspace = false;
        duplicateWorkspace = false;
        renameWorkspace = false;
        //Title bar
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
                String title = frame.getTitle();
                title = title.substring(0, title.indexOf(" - "));
                frame.setTitle(title);
            }
        });
    }
    return true;
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) JFrame(javax.swing.JFrame) FileObject(org.openide.filesystems.FileObject)

Example 7 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project gephi by gephi.

the class CommandLineProcessor method process.

@Override
public void process(Env env, Map values) throws CommandException {
    List<String> filenameList = new ArrayList<>();
    Object obj = values.get(openOption);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    obj = values.get(openOption2);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    try {
        for (int i = 0; i < filenameList.size(); i++) {
            File file = new File(filenameList.get(i));
            if (!file.isAbsolute()) {
                file = new File(env.getCurrentDirectory(), filenameList.get(i));
            }
            FileObject fileObject = FileUtil.toFileObject(file);
            if (!file.exists()) {
                NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotFound", file.getName()), NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(msg);
                return;
            }
            if (fileObject.hasExt(GEPHI_EXTENSION)) {
                ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                try {
                    pc.openProject(file);
                } catch (Exception ew) {
                    ew.printStackTrace();
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
                return;
            } else {
                ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                    importController.importFile(fileObject);
                } else {
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotSupported"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
            }
        }
    } catch (OutOfMemoryError ex) {
        System.gc();
        NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    } catch (Exception ex) {
        ex.printStackTrace();
        NotifyDescriptor nd = new NotifyDescriptor.Message("CommandLineParsing " + ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : ArrayList(java.util.ArrayList) CommandException(org.netbeans.api.sendopts.CommandException) NotifyDescriptor(org.openide.NotifyDescriptor) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 8 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project gephi by gephi.

the class MemoryStarvationManager method handleNotification.

@Override
public void handleNotification(Notification n, Object o) {
    if (messageDelivered) {
        return;
    }
    CompositeData cd = (CompositeData) n.getUserData();
    MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
    suspendThreads();
    messageDelivered = true;
    //Dialog
    if (canIncreaseMemory()) {
        String messageBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.message", getMb(Runtime.getRuntime().maxMemory()) + " mb", getMb(getMaximumXmx()) + " mb");
        String titleBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.title");
        String increaseAndRestart = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.button");
        String cancelBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.cancel");
        NotifyDescriptor msg = new NotifyDescriptor(messageBundle, titleBundle, NotifyDescriptor.YES_NO_CANCEL_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[] { increaseAndRestart, cancelBundle }, increaseAndRestart);
        if (DialogDisplayer.getDefault().notify(msg) != increaseAndRestart) {
            resumeThreads();
            return;
        }
        String xmx = getMb(getMaximumXmx()) + "m";
        try {
            updateConfiguration(xmx);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    } else {
        String messageBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.message", getMb(Runtime.getRuntime().maxMemory()) + " mb");
        String titleBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.title");
        String saveAndRestart = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.button");
        String cancelBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.cancel");
        NotifyDescriptor msg = new NotifyDescriptor(messageBundle, titleBundle, NotifyDescriptor.YES_NO_CANCEL_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[] { saveAndRestart, cancelBundle }, saveAndRestart);
        if (DialogDisplayer.getDefault().notify(msg) != saveAndRestart) {
            resumeThreads();
            return;
        }
    }
    interruptThreads();
    freeSomeMemory();
    saveProject();
    restart();
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException)

Example 9 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project gephi by gephi.

the class Delete method execute.

@Override
public void execute() {
    NotifyDescriptor.Confirmation notifyDescriptor = new NotifyDescriptor.Confirmation(NbBundle.getMessage(Delete.class, "GraphContextMenu.Delete.message"), NbBundle.getMessage(Delete.class, "GraphContextMenu.Delete.message.title"), NotifyDescriptor.YES_NO_OPTION);
    if (DialogDisplayer.getDefault().notify(notifyDescriptor).equals(NotifyDescriptor.YES_OPTION)) {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        gec.deleteNodes(nodes);
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) GraphElementsController(org.gephi.datalab.api.GraphElementsController)

Example 10 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project ACS by ACS-Community.

the class MainLauncherAction method performAction.

public void performAction() {
    if (mainClassName == null) {
        NotifyDescriptor usage = new NotifyDescriptor.Message("Main Class not set, use the command line option -J-D" + MAIN_CLASS_OPTION + " to set it");
        GPManager.notify(usage);
        return;
    }
    try {
        Class mainClass = Class.forName(MAIN_CLASS_OPTION);
        Method mainMeth = mainClass.getDeclaredMethod("main", new Class[] { String[].class });
        mainMeth.invoke(null, null);
    } catch (ClassNotFoundException ex) {
        NotifyDescriptor err = new NotifyDescriptor.Message("class not found " + MAIN_CLASS_OPTION);
        GPManager.notify(err);
    } catch (NoSuchMethodException ex) {
        NotifyDescriptor err = new NotifyDescriptor.Message("class " + MAIN_CLASS_OPTION + " has no main(String[]) method");
        GPManager.notify(err);
    } catch (IllegalAccessException ex) {
        NotifyDescriptor err = new NotifyDescriptor.Message("error invoking main on class " + MAIN_CLASS_OPTION);
        GPManager.notify(err);
    } catch (InvocationTargetException ex) {
        // the main method has been executed and thrown an exception
        GPManager.notify(GPManager.EXCEPTION, ex);
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

NotifyDescriptor (org.openide.NotifyDescriptor)10 FileObject (org.openide.filesystems.FileObject)2 File (java.io.File)1 IOException (java.io.IOException)1 MemoryNotificationInfo (java.lang.management.MemoryNotificationInfo)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Handler (java.util.logging.Handler)1 CompositeData (javax.management.openmbean.CompositeData)1 JFrame (javax.swing.JFrame)1 JPanel (javax.swing.JPanel)1 GraphElementsController (org.gephi.datalab.api.GraphElementsController)1 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)1 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)1 Edge (org.gephi.graph.api.Edge)1 Graph (org.gephi.graph.api.Graph)1 GraphController (org.gephi.graph.api.GraphController)1 GraphModel (org.gephi.graph.api.GraphModel)1 CommandException (org.netbeans.api.sendopts.CommandException)1