Example usage for javax.swing JOptionPane YES_NO_OPTION

List of usage examples for javax.swing JOptionPane YES_NO_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane YES_NO_OPTION.

Prototype

int YES_NO_OPTION

To view the source code for javax.swing JOptionPane YES_NO_OPTION.

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:com.g2inc.scap.editor.gui.windows.EditorMainWindow.java

@Override
public void windowClosing(WindowEvent arg0) {
    // save window location and bounds
    Point myLocation = getLocation();
    Dimension mySize = getSize();

    guiProps.setProperty(EditorConfiguration.PROPERTY_MAIN_WINDOW_LOCATION_X, myLocation.x + "");
    guiProps.setProperty(EditorConfiguration.PROPERTY_MAIN_WINDOW_LOCATION_Y, myLocation.y + "");

    guiProps.setProperty(EditorConfiguration.PROPERTY_MAIN_WINDOW_SIZE_X, mySize.width + "");
    guiProps.setProperty(EditorConfiguration.PROPERTY_MAIN_WINDOW_SIZE_Y, mySize.height + "");

    guiProps.save();/*from   ww  w  .  ja  v  a2  s.c o  m*/

    // cycle through open internal frames(documents)
    // and see if any of them need to be saved
    JInternalFrame[] openFrames = desktopPane.getAllFrames();

    if (openFrames != null && openFrames.length > 0) {
        for (int x = 0; x < openFrames.length; x++) {
            JInternalFrame internalWin = openFrames[x];
            if (internalWin instanceof EditorForm) {
                EditorForm ef = (EditorForm) internalWin;
                if (ef.getDocument() == null) {
                    continue;
                }

                String filename = ef.getDocument().getFilename();

                if (filename == null) {
                    continue;
                }

                if (ef.isDirty()) {
                    Object[] options = { EditorMessages.FILE_CHOOSER_BUTTON_TEXT_SAVE, "Discard" };

                    String message = filename
                            + " has unsaved changes.  Do you want to save or discard changes?";
                    String dTitle = "Unsaved changes";

                    int n = JOptionPane.showOptionDialog(this, message, dTitle, JOptionPane.YES_NO_OPTION,
                            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

                    if (n == JOptionPane.DEFAULT_OPTION || n == JOptionPane.YES_OPTION) {
                        final GenericProgressDialog progress = new GenericProgressDialog(
                                EditorMainWindow.getInstance(), true);
                        progress.setMessage("Saving changes to " + ef.getDocument().getFilename());
                        try {
                            final SCAPDocument sdoc = (SCAPDocument) ef.getDocument();

                            Runnable r = new Runnable() {
                                @Override
                                public void run() {
                                    try {
                                        sdoc.save();
                                    } catch (Exception e) {
                                        progress.setException(e);
                                    }
                                }
                            };

                            progress.setRunnable(r);

                            progress.pack();
                            progress.setLocationRelativeTo(this);
                            progress.setVisible(true);

                            if (progress.getException() != null) {
                                throw (progress.getException());
                            }

                            ef.setDirty(false);
                        } catch (Exception e) {
                            LOG.error("Error saving file " + filename, e);
                            String errMessage = filename + " couldn't be saved.  An error occured: "
                                    + e.getMessage();
                            dTitle = "File save error";

                            EditorUtil.showMessageDialog(this, errMessage, dTitle, JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            }
        }
    }
}

From source file:musite.ui.MusiteResultPanel.java

public boolean saveResult(boolean showConfirm) {
    JFileChooser fc = new JFileChooser(MusiteInit.defaultPath);

    // TODO: windows reserverd
    String fileName = panelName.replaceAll("[" + StringUtil.toOct("|\\?*<\":>+[]/") + "]+", "_");
    fc.setSelectedFile(new File(MusiteInit.defaultPath + File.separator + fileName + ".pred.xml.gz"));

    ArrayList<String> exts = new ArrayList<String>(2);
    exts.add("xml");
    exts.add("xml.gz");
    fc.addChoosableFileFilter(new FileExtensionsFilter(exts, "Prediction XML file (.xml, .xml.gz)"));

    exts = new ArrayList<String>(2);
    exts.add("pred.xml");
    exts.add("pred.xml.gz");
    fc.addChoosableFileFilter(new FileExtensionsFilter(exts, "Prediction result file (pred.xml, pred.xml.gz)"));

    //fc.setAcceptAllFileFilterUsed(true);
    fc.setDialogTitle("Save the the result to...");
    int returnVal = fc.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        MusiteInit.defaultPath = file.getParent();

        String filePath = MusiteInit.defaultPath + File.separator + file.getName();

        //            if (!filePath.toLowerCase().endsWith(".xml")&&!filePath.toLowerCase().endsWith(".xml.gz")) {
        //                filePath += ".pred.xml.gz";
        //            }

        if (IOUtil.fileExist(filePath)) {
            int ret = JOptionPane.showConfirmDialog(this, "Are you sure to replace the existing file?",
                    "Relace the existing file?", JOptionPane.YES_NO_OPTION);
            if (ret == JOptionPane.NO_OPTION)
                return false;
        }/*from  w ww.j a v a2 s  .  co  m*/

        PredictionResultXMLWriter writer = PredictionResultXMLWriter.createWriter();
        WriteTask task = new WriteTask(result, writer, filePath);

        TaskUtil.execute(task);
        if (task.success()) {
            if (showConfirm)
                JOptionPane.showMessageDialog(this, "Result saved!");
            saved = true;
            return true;
        } else {
            JOptionPane.showMessageDialog(this, "Failed to save the result.");
            return false;
        }
    } else {
        return false;
    }
}

From source file:corelyzer.ui.CorelyzerApp.java

private void onDeleteSelectedSections(final int[] rows) {
    String mesg = "Are you sure you want to remove all\n" + "selected sections?";

    Object[] options = { "Cancel", "Yes" };
    int ans = JOptionPane.showOptionDialog(app.getMainFrame(), mesg, "Confirmation", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);

    if (ans == 1) {
        CoreGraph cg = CoreGraph.getInstance();
        TrackSceneNode t = cg.getCurrentTrack();

        if (t != null) {
            int tid = t.getId();

            // delete in reverse order
            for (int i = rows.length - 1; i >= 0; i--) {
                int row = rows[i];

                CoreSection cs = t.getCoreSection(row);
                if (cs != null) {
                    int csid = cs.getId();
                    controller.deleteSection(tid, csid);
                }//from   w  ww  .  j  a  v  a  2 s.  c  o m
            }
        }
    }
}

From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java

/**
 * Launches dialog for Importing and Exporting Forms and Resources.
 *//*from   w ww.  j ava  2  s  .com*/
public static boolean askBeforeStartingTool() {
    if (SubPaneMgr.getInstance().aboutToShutdown()) {
        Object[] options = { getResourceString("CONTINUE"), //$NON-NLS-1$
                getResourceString("CANCEL") //$NON-NLS-1$
        };
        return JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(getTopWindow(),
                getLocalizedMessage(getI18NKey("REI_MSG")), //$NON-NLS-1$
                getResourceString(getI18NKey("REI_TITLE")), //$NON-NLS-1$
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
    }
    return false;
}

From source file:de.juwimm.cms.util.Communication.java

@SuppressWarnings("unchecked")
public boolean removeViewComponent(int intViewComponentId, String viewComponentName, byte onlineState) {
    boolean retVal = false;

    try {//from  ww  w .ja v a2 s  .co m
        // CHECK IF THIS NODE CONTAINS SUBNODES
        ViewIdAndInfoTextValue[] str = getAllChildrenNamesWithUnit(intViewComponentId);
        String units = "";
        if (str != null && str.length > 0) {
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < str.length; i++) {
                sb.append(str[i].getInfoText().trim()).append("\n");
            }
            units = sb.toString();
        }
        if (!units.equalsIgnoreCase("")) {
            if (!isUserInRole(UserRights.SITE_ROOT)) {
                // dazwischen, damit sparen wir uns das zweite...
                String msg = Messages.getString("comm.removevc.containsunitsandcannotremove", units);
                JOptionPane.showMessageDialog(UIConstants.getMainFrame(), msg, rb.getString("dialog.title"),
                        JOptionPane.ERROR_MESSAGE);
                return false;
            }
            units = Messages.getString("comm.removevc.header_units", units);
        }

        String refVcs = "";
        ViewComponentValue[] refDao = getViewComponentsWithReferenceToViewComponentId(intViewComponentId);
        if (refDao != null && refDao.length > 0) {
            StringBuffer sb = new StringBuffer();
            for (int j = 0; j < refDao.length; j++) {
                if (refDao[j].getViewType() == Constants.VIEW_TYPE_INTERNAL_LINK) {
                    // InternalLink in the Tree
                    sb.append(Messages.getString("comm.removevc.refvc.internallink",
                            ("\"" + refDao[j].getDisplayLinkName() + "\""),
                            ("\"" + refDao[j].getMetaData().trim() + "\""))).append("\n");
                } else if (refDao[j].getViewType() == Constants.VIEW_TYPE_SYMLINK) {
                    // reference though Symlink in the Tree
                    sb.append(Messages.getString("comm.removevc.refvc.symlink",
                            ("\"" + refDao[j].getDisplayLinkName() + "\""),
                            ("\"" + refDao[j].getMetaData().trim() + "\""))).append("\n");
                } else {
                    // reference through links in the content
                    sb.append(Messages.getString("comm.removevc.refvc.content",
                            ("\"" + refDao[j].getDisplayLinkName() + "\""),
                            ("\"" + refDao[j].getMetaData().trim() + "\""))).append("\n");
                }
            }
            refVcs = sb.toString();
        }

        if (!refVcs.equals("")) {
            refVcs = Messages.getString("comm.removevc.header_refvcs", refVcs);
        }

        String teaserText = "";
        boolean teaserReferenced = false;
        try {
            StringBuilder refTeaser = new StringBuilder("");
            XmlSearchValue[] xmlSearchValues = this.searchXml(getSiteId(), "//teaserRef");
            if (xmlSearchValues != null && xmlSearchValues.length > 0) {
                // herausfinden, ob es sich um DIESEN Teaser handelt
                String resultRootStartElement = "<searchTeaserResult>";
                String resultRootEndElement = "</searchTeaserResult>";
                for (int i = 0; i < xmlSearchValues.length; i++) {
                    StringBuilder stringBuilder = new StringBuilder(xmlSearchValues[i].getContent());
                    stringBuilder.insert(0, resultRootStartElement);
                    stringBuilder.append(resultRootEndElement);
                    Document doc = XercesHelper.string2Dom(stringBuilder.toString());
                    Iterator<Element> teaserIterator = XercesHelper.findNodes(doc,
                            "searchTeaserResult/teaserRef");
                    while (teaserIterator.hasNext()) {
                        Element element = teaserIterator.next();
                        String viewComponentIdValue = element.getAttribute("viewComponentId");
                        if (viewComponentIdValue != null && viewComponentIdValue.trim().length() > 0) {
                            if (intViewComponentId == (new Integer(viewComponentIdValue)).intValue()) {
                                teaserReferenced = true;
                                refTeaser.append(this.getPathForViewComponentId(
                                        xmlSearchValues[i].getViewComponentId().intValue()) + "\n");
                            }
                        }
                    }
                }
                if (teaserReferenced) {
                    teaserText = Messages.getString("comm.removevc.header.teaser", refTeaser.toString());
                }
            }
        } catch (Exception exception) {
            log.error(exception.getMessage(), exception);
        }
        String msgHeader = "";
        if (onlineState == Constants.ONLINE_STATUS_UNDEF || onlineState == Constants.ONLINE_STATUS_OFFLINE) {
            msgHeader = rb.getString("comm.removevc.header_offline");
        } else {
            msgHeader = rb.getString("comm.removevc.header_online");
        }

        String msgstr = msgHeader + units + refVcs + teaserText;

        int i = JOptionPane.showConfirmDialog(UIConstants.getMainFrame(), msgstr, rb.getString("dialog.title"),
                JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

        if (i == JOptionPane.YES_OPTION) {
            if (onlineState == Constants.ONLINE_STATUS_UNDEF
                    || onlineState == Constants.ONLINE_STATUS_OFFLINE) {
                getClientService().removeViewComponent(Integer.valueOf(intViewComponentId), true);
                /*
                 * } else { // nothing at the moment, the code for here is
                 * currently in PanTree actionViewComponentPerformed
                 */
            }
            retVal = true;
        }
    } catch (Exception exe) {
        log.error("Error removing vc", exe);
    }

    if (retVal) {
        try {
            checkOutPages.remove(new Integer(getViewComponent(intViewComponentId).getReference()));
        } catch (Exception exe) {
        }
        UIConstants.setStatusInfo(rb.getString("comm.removevc.statusinfo"));
    }
    return retVal;
}

From source file:net.pms.newgui.NavigationShareTab.java

private PanelBuilder initSharedFoldersGuiComponents(CellConstraints cc) {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(SHARED_FOLDER_COL_SPEC, orientation);

    FormLayout layoutFolders = new FormLayout(colSpec, SHARED_FOLDER_ROW_SPEC);
    PanelBuilder builderFolder = new PanelBuilder(layoutFolders);
    builderFolder.opaque(true);/*  w w w  .j av a 2 s.c  o  m*/

    JComponent cmp = builderFolder.addSeparator(Messages.getString("FoldTab.7"),
            FormLayoutUtil.flip(cc.xyw(1, 1, 7), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    folderTableModel = new SharedFoldersTableModel();
    sharedFolders = new JTable(folderTableModel);

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItemMarkPlayed = new JMenuItem(Messages.getString("FoldTab.75"));
    JMenuItem menuItemMarkUnplayed = new JMenuItem(Messages.getString("FoldTab.76"));

    menuItemMarkPlayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, true);
        }
    });

    menuItemMarkUnplayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, false);
        }
    });

    popupMenu.add(menuItemMarkPlayed);
    popupMenu.add(menuItemMarkUnplayed);

    sharedFolders.setComponentPopupMenu(popupMenu);

    /* An attempt to set the correct row height adjusted for font scaling.
     * It sets all rows based on the font size of cell (0, 0). The + 4 is
     * to allow 2 pixels above and below the text. */
    DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) sharedFolders.getCellRenderer(0, 0);
    FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
    sharedFolders.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
    sharedFolders.setIntercellSpacing(new Dimension(8, 2));

    final JPanel tmpsharedPanel = sharedPanel;

    addButton.setToolTipText(Messages.getString("FoldTab.9"));
    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showOpenDialog((Component) e.getSource());
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                int firstSelectedRow = sharedFolders.getSelectedRow();
                if (firstSelectedRow >= 0) {
                    ((SharedFoldersTableModel) sharedFolders.getModel()).insertRow(firstSelectedRow,
                            new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                } else {
                    ((SharedFoldersTableModel) sharedFolders.getModel())
                            .addRow(new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                }
            }
        }
    });
    builderFolder.add(addButton, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));

    removeButton.setToolTipText(Messages.getString("FoldTab.36"));
    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = sharedFolders.getSelectedRows();
            if (rows.length > 0) {
                if (rows.length > 1) {
                    if (JOptionPane.showConfirmDialog(tmpsharedPanel,
                            String.format(Messages.getString("SharedFolders.ConfirmRemove"), rows.length),
                            Messages.getString("Dialog.Confirm"), JOptionPane.YES_NO_OPTION,
                            JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    }
                }
                for (int i = rows.length - 1; i >= 0; i--) {
                    PMS.get().getDatabase().removeMediaEntriesInFolder(
                            (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0));
                    ((SharedFoldersTableModel) sharedFolders.getModel()).removeRow(rows[i]);
                }
            }
        }
    });
    builderFolder.add(removeButton, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));

    arrowDownButton.setToolTipText(Messages.getString("SharedFolders.ArrowDown"));
    arrowDownButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < sharedFolders.getRowCount() - 1; i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i + 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i + 1, 1);
                    sharedFolders.changeSelection(i + 1, 1, false, false);

                    break;
                }
            }
        }
    });
    builderFolder.add(arrowDownButton, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));

    arrowUpButton.setToolTipText(Messages.getString("SharedFolders.ArrowUp"));
    arrowUpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < sharedFolders.getRowCount(); i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i - 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i - 1, 1);
                    sharedFolders.changeSelection(i - 1, 1, false, false);

                    break;

                }
            }
        }
    });
    builderFolder.add(arrowUpButton, FormLayoutUtil.flip(cc.xy(5, 3), colSpec, orientation));

    scanButton.setToolTipText(Messages.getString("FoldTab.2"));
    scanBusyIcon.start();
    scanBusyDisabledIcon.start();
    scanButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (configuration.getUseCache()) {
                DLNAMediaDatabase database = PMS.get().getDatabase();

                if (database != null) {
                    if (database.isScanLibraryRunning()) {
                        int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("FoldTab.10"),
                                Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
                        if (option == JOptionPane.YES_OPTION) {
                            database.stopScanLibrary();
                            looksFrame.setStatusLine(Messages.getString("FoldTab.41"));
                            scanButton.setEnabled(false);
                            scanButton.setToolTipText(Messages.getString("FoldTab.41"));
                        }
                    } else {
                        database.scanLibrary();
                        scanButton.setIcon(scanBusyIcon);
                        scanButton.setRolloverIcon(scanBusyRolloverIcon);
                        scanButton.setPressedIcon(scanBusyPressedIcon);
                        scanButton.setDisabledIcon(scanBusyDisabledIcon);
                        scanButton.setToolTipText(Messages.getString("FoldTab.40"));
                    }
                }
            }
        }
    });

    /*
     * Hide the scan button in basic mode since it's better to let it be done in
     * realtime.
     */
    if (!configuration.isHideAdvancedOptions()) {
        builderFolder.add(scanButton, FormLayoutUtil.flip(cc.xy(6, 3), colSpec, orientation));
    }

    scanButton.setEnabled(configuration.getUseCache());

    isScanSharedFoldersOnStartup = new JCheckBox(Messages.getString("NetworkTab.StartupScan"),
            configuration.isScanSharedFoldersOnStartup());
    isScanSharedFoldersOnStartup.setToolTipText(Messages.getString("NetworkTab.StartupScanTooltip"));
    isScanSharedFoldersOnStartup.setContentAreaFilled(false);
    isScanSharedFoldersOnStartup.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setScanSharedFoldersOnStartup((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    builderFolder.add(isScanSharedFoldersOnStartup, FormLayoutUtil.flip(cc.xy(7, 3), colSpec, orientation));

    updateSharedFolders();

    JScrollPane pane = new JScrollPane(sharedFolders);
    Dimension d = sharedFolders.getPreferredSize();
    pane.setPreferredSize(new Dimension(d.width, sharedFolders.getRowHeight() * 2));
    builderFolder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 5, 7, CellConstraints.DEFAULT, CellConstraints.FILL),
            colSpec, orientation));

    return builderFolder;
}

From source file:com.sshtools.sshterm.SshTerminalPanel.java

public boolean canClose() {
    if (session != null) {
        setFullScreenMode(false);//from   www .  j a v a  2 s .  com

        if (JOptionPane.showConfirmDialog(this, "Close the current session and exit?", "Exit Application",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
            return false;
        }

        /*if (browserFrame != null) {
          if (! ( (SessionProviderFrame) browserFrame).canExit()) {
            return false;
          }
               }*/
    }

    return true;
}

From source file:gdt.data.entity.ArchiveHandler.java

/**
 * Insert entities from the archive file into the database. 
 * @param  console main console instance
 * @param entihome$ the root directory of the database
 * @param file$ the path of the archive file. 
 * @return the key of 'undo' entity./*from   w w w.  j a v a  2  s  . c om*/
 */
public static String insertEntities(JMainConsole console, String entihome$, String file$) {
    try {
        if (!ARCHIVE_CONTENT_ENTITIES.equals(detectContentOfArchive(file$))) {
            System.out.println("ArchiveHandler:insertEntites:wrong archive=" + file$);
            return null;
        }

        File cache = new File(System.getProperty("user.home") + "/.entigrator/cache");
        if (!cache.exists())
            cache.mkdirs();
        FileExpert.clear(cache.getPath());
        ArchiveHandler.extractEntities(cache.getPath(), file$);
        Entigrator entigrator = console.getEntigrator(entihome$);
        Sack undo = ArchiveHandler.prepareUndo(entigrator, cache.getPath());
        String undoLocator$ = EntityHandler.getEntityLocator(entigrator, undo);
        JEntityPrimaryMenu.reindexEntity(console, undoLocator$);
        ArchiveHandler.fillUndo(entigrator, undo);
        int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Keep existing entities ?",
                "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION)
            ArchiveHandler.insertCache(entigrator, cache.getPath(), true);
        else
            ArchiveHandler.insertCache(entigrator, cache.getPath(), false);
        String[] sa = undo.elementList("entity");
        if (sa != null) {
            String entityLocator$;
            for (String s : sa) {
                entityLocator$ = EntityHandler.getEntityLocatorAtKey(entigrator, s);
                JEntityPrimaryMenu.reindexEntity(console, entityLocator$);
            }
        }
        return undo.getKey();
    } catch (Exception ee) {
        Logger.getLogger(ArchiveHandler.class.getName()).severe(ee.toString());
        return null;
    }
}

From source file:it.iit.genomics.cru.igb.bundles.mi.business.MIWorker.java

/**
 * Adds a component to a JTabbedPane with a little close tab" button on the
 * right side of the tab./*from  w  ww  .  ja  v a2  s.c o m*/
 *
 * @param tabbedPane
 *            the JTabbedPane
 * @param c
 *            any JComponent
 * @param title
 *            the title for the tab
 */
public static void addClosableTab(final JTabbedPane tabbedPane, final JComponent c, final String title) {
    // Add the tab to the pane without any label
    tabbedPane.addTab(null, c);
    int pos = tabbedPane.indexOfComponent(c);

    // Create a FlowLayout that will space things 5px apart
    FlowLayout f = new FlowLayout(FlowLayout.CENTER, 5, 0);

    // Make a small JPanel with the layout and make it non-opaque
    JPanel pnlTab = new JPanel(f);
    pnlTab.setOpaque(false);

    // Add a JLabel with title and the left-side tab icon
    JLabel lblTitle = new JLabel(title);

    // Create a JButton for the close tab button
    JButton btnClose = new JButton("x");
    // btnClose.setOpaque(false);
    int size = 17;
    btnClose.setPreferredSize(new Dimension(size, size));
    btnClose.setToolTipText("close this tab");
    // Make the button looks the same for all Laf's
    btnClose.setUI(new BasicButtonUI());
    // Make it transparent
    btnClose.setContentAreaFilled(false);
    // No need to be focusable
    btnClose.setFocusable(false);
    btnClose.setBorder(BorderFactory.createEtchedBorder());
    btnClose.setBorderPainted(false);
    // Making nice rollover effect
    // we use the same listener for all buttons
    btnClose.setRolloverEnabled(true);
    // Close the proper tab by clicking the button

    // Configure icon and rollover icon for button
    btnClose.setRolloverEnabled(true);

    // Set border null so the button doesnt make the tab too big
    btnClose.setBorder(null);
    // Make sure the button cant get focus, otherwise it looks funny
    btnClose.setFocusable(false);

    // Put the panel together
    pnlTab.add(lblTitle);
    pnlTab.add(btnClose);

    // Add a thin border to keep the image below the top edge of the tab
    // when the tab is selected
    pnlTab.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
    // Now assign the component for the tab
    tabbedPane.setTabComponentAt(pos, pnlTab);

    // Add the listener that removes the tab
    ActionListener listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(new JFrame(),
                    "Are you sure you want to remove this tab? All results will be lost!", "Remove tab",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                tabbedPane.remove(c);
            }
        }
    };
    btnClose.addActionListener(listener);

    // Optionally bring the new tab to the front
    tabbedPane.setSelectedComponent(c);

}

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

/**
 * Discard concept.//from ww  w. j a  va2 s .com
 */
public void conceptDiscard() {
    if (MindRaider.profile.getActiveOutlineUri() == null) {
        JOptionPane.showMessageDialog(OutlineJPanel.this,
                Messages.getString("NotebookOutlineJPanel.toDiscardConceptTheNotebookMustBeOpened"),
                Messages.getString("NotebookOutlineJPanel.discardConceptError"), JOptionPane.ERROR_MESSAGE);
        return;
    }

    // move concept up in the tree
    DefaultMutableTreeNode node = getSelectedTreeNode();
    if (node != null) {
        if (node.isLeaf() && node.getParent() != null) {
            try {
                if (JOptionPane.showConfirmDialog(MindRaider.mainJFrame,
                        Messages.getString("NotebookOutlineJPanel.doYouWantToDiscardConcept", node.toString()),
                        Messages.getString("NotebookOutlineJPanel.discardConcept"),
                        JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                    return;
                }

                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                String notebookUri = MindRaider.outlineCustodian.getActiveOutlineResource().resource
                        .getMetadata().getUri().toString();
                MindRaider.noteCustodian.discard(notebookUri, ((OutlineNode) parent).getUri(),
                        ((OutlineNode) node).getUri());
                refresh();
                MindRaider.spidersGraph.selectNodeByUri(notebookUri);
                MindRaider.spidersGraph.renderModel();

                conceptJPanel.clear();
            } catch (Exception e1) {
                logger.debug(Messages.getString("NotebookOutlineJPanel.unableToDiscardConcept"), e1);
                StatusBar.show(Messages.getString("NotebookOutlineJPanel.unableToDiscardConcept"));
            }
        } else {
            StatusBar.show(Messages.getString("NotebookOutlineJPanel.discardingOnlyLeafConcepts"));
            JOptionPane.showMessageDialog(OutlineJPanel.this,
                    Messages.getString("NotebookOutlineJPanel.discardingOnlyLeafConcepts"),
                    "Concept Discard Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
    } else {
        logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected"));
    }
}