Java 类org.openide.util.UserCancelException 实例源码

项目:incubator-netbeans    文件:NodeOperationImpl.java   
public Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top) throws UserCancelException {
    // XXX rootTitle and acceptor currently ignored
    JDialog d = new JDialog();
    d.setTitle(title);
    d.setModal(true);
    d.getContentPane().setLayout(new BorderLayout());
    EP p = new EP();
    p.getExplorerManager().setRootContext(root);
    p.setLayout(new BorderLayout());
    p.add(new BeanTreeView(), BorderLayout.CENTER);
    d.getContentPane().add(p, BorderLayout.CENTER);
    if (top != null) {
        d.getContentPane().add(top, BorderLayout.NORTH);
    }
    d.pack();
    d.setVisible(true);
    Node[] nodes = p.getExplorerManager().getSelectedNodes();
    d.dispose();
    return nodes;
}
项目:incubator-netbeans    文件:PasteAction.java   
public void actionPerformed(ActionEvent ev) {
    try {
        Transferable trans = t.paste();
        Clipboard clipboard = getClipboard();

        if (trans != null) {
            ClipboardOwner owner = (trans instanceof ClipboardOwner) ? (ClipboardOwner) trans
                                                                     : new StringSelection(""); // NOI18N
            clipboard.setContents(trans, owner);
        }
    } catch (UserCancelException exc) {
        // ignore - user just pressed cancel in some dialog....
    } catch (IOException e) {
        Exceptions.printStackTrace(e);
    } finally {
        EventQueue.invokeLater(this);
    }
}
项目:incubator-netbeans    文件:HtmlDataObject.java   
/** New instance.
 * @param pf primary file object for this data object
 * @param loader the data loader creating it
 * @exception DataObjectExistsException if there was already a data object for it
 */
public HtmlDataObject(FileObject pf, UniFileLoader loader) throws DataObjectExistsException {
    super(pf, loader);
    CookieSet set = getCookieSet();
    set.add(HtmlEditorSupport.class, this);
    set.add(ViewSupport.class, this);
    set.assign(SaveAsCapable.class, new SaveAsCapable() {
        public void saveAs( FileObject folder, String fileName ) throws IOException {
            HtmlEditorSupport es = getCookie( HtmlEditorSupport.class );
            try {
                es.updateEncoding();
                es.saveAs( folder, fileName );
            } catch (UserCancelException e) {
                //ignore, just not save anything
            }
        }
    });

    set.assign(FileEncodingQueryImplementation.class, new FileEncodingQueryImpl());

    //add check/validate xml cookies
    InputSource in = DataObjectAdapters.inputSource(this);
    set.add(new ValidateXMLSupport(in));
    set.add(new CheckXMLSupport(in));

}
项目:ireport-fork    文件:OpenFileAction.java   
/**
 * Displays the specified file chooser and returns a list of selected files.
 *
 * @param  chooser  file chooser to display
 * @return  array of selected files,
 * @exception  org.openide.util.UserCancelException
 *                     if the user cancelled the operation
 */
public static File[] chooseFilesToOpen(JFileChooser chooser)
        throws UserCancelException {
    File[] files;
    do {
        int selectedOption = chooser.showOpenDialog(
            WindowManager.getDefault().getMainWindow());

        if (selectedOption != JFileChooser.APPROVE_OPTION) {
            throw new UserCancelException();
        }

        // If the chooser is not configured for multi files, then use
        // File file = chooser.getSelectedFile();
        files = chooser.getSelectedFiles();
    } while (files.length == 0);
    return files;
}
项目:ireport-fork    文件:OpenFileAction.java   
/**
 * {@inheritDoc} Displays a file chooser dialog
 * and opens the selected files.
 */
public void performAction() {
     JFileChooser chooser = prepareFileChooser();
     File[] files;
     try {
         files = chooseFilesToOpen(chooser);
     } catch (UserCancelException ex) {
         return;
     }

     for (int i = 0; i < files.length; i++) {
        // Small hack ... OpenFile is User Utilities, which is a private API
        //
        // OpenFile.openFile(files[i], -1);
        open(files[i]);
    }

                // Save the last path used for the chooser..
                if (files.length > 0)
                {
                    String dir = files[0].getParent();
                    IReportManager.getPreferences().put( IReportManager.CURRENT_DIRECTORY, dir);
                }
}
项目:studio    文件:DragDropUtilities.java   
/** Performs the drop. Performs paste on given paste type.
*/
static void performDrop (PasteType type) {
    //System.out.println("performing drop...."+type); // NOI18N
    try {
        Transferable trans = type.paste();
        /*Clipboard clipboard = T opManager.getDefault().getClipboard();
        if (trans != null) {
          ClipboardOwner owner = trans instanceof ClipboardOwner ?
            (ClipboardOwner)trans
          :
            new StringSelection ("");
          clipboard.setContents(trans, owner);
    }*/
    } catch (UserCancelException exc) {
        // ignore - user just pressed cancel in some dialog....
    } catch (java.io.IOException e) {
        ErrorManager.getDefault ().notify(e);
    }
}
项目:studio    文件:SaveAsTemplateAction.java   
protected void performAction (Node[] activatedNodes) {
    // prepare variables
    NodeAcceptor acceptor = FolderNodeAcceptor.getInstance();
    String title = NbBundle.getMessage(SaveAsTemplateAction.class, "Title_SaveAsTemplate");
    String rootTitle = NbBundle.getMessage(SaveAsTemplateAction.class, "CTL_SaveAsTemplate");
    Node templatesNode = NewTemplateAction.getTemplateRoot ();
    Node[] selected;
    // ask user: where to save the templates?
    try {
        selected = NodeOperation.getDefault().
                   select(title, rootTitle, templatesNode, acceptor, null);
    } catch (UserCancelException ex) {
        // user cancelled the operation
        return;
    }
    // create & save them all
    // we know DataFolder and DataObject cookies must be supported
    // so we needn't check for null values
    DataFolder targetFolder =
        (DataFolder)selected[0].getCookie(DataFolder.class);
    for (int i = 0; i < activatedNodes.length; i++ ) {
        createNewTemplate(
            (DataObject)activatedNodes[i].getCookie(DataObject.class),
            targetFolder);
    }
}
项目:incubator-netbeans    文件:NodeOperation.java   
/** Open a modal Explorer accepting only a single node.
 * @param title title of the dialog
 * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
 * @param root root node to explore
 * @return the selected node
 *
 * @exception UserCancelException if the selection is interrupted by the user
 * @see #select(String, String, Node, NodeAcceptor)
 */
public final Node select(String title, String rootTitle, Node root)
throws UserCancelException {
    return select(
        title, rootTitle, root,
        new NodeAcceptor() {
            public boolean acceptNodes(Node[] nodes) {
                return nodes.length == 1;
            }
        }
    )[0];
}
项目:incubator-netbeans    文件:HtmlEditorSupport.java   
/**
 * Implements
 * <code>SaveCookie</code> interface.
 */
@Override
public void save() throws IOException {
    try {
        saveDocument();
    } catch (UserCancelException uce) {
        //just ignore
    }
}
项目:incubator-netbeans    文件:OpenFileAction.java   
/**
 * Displays the specified file chooser and returns a list of selected files.
 *
 * @param  chooser  file chooser to display
 * @return  array of selected files,
 * @exception  org.openide.util.UserCancelException
 *                     if the user cancelled the operation
 */
public static File[] chooseFilesToOpen(JFileChooser chooser)
        throws UserCancelException {
    File[] files;
    do {
        int selectedOption = chooser.showOpenDialog(
            WindowManager.getDefault().getMainWindow());

        if (selectedOption != JFileChooser.APPROVE_OPTION) {
            throw new UserCancelException();
        }
        files = chooser.getSelectedFiles();
    } while (files.length == 0);
    return files;
}
项目:incubator-netbeans    文件:SelectorUtils.java   
/**
  * Brings up a modal windows for selection of a resource bundle from
  * the given project.
  * @param prj the project to select from
  * @return DataObject representing the selected bundle file or null
  */
 static public DataObject selectBundle(Project prj, FileObject file) {
   try {
     Node root = bundlesNode(prj, file, true);

     Node[] selectedNodes= 
NodeOperation.getDefault().
select(
       Util.getString("CTL_SelectPropDO_Dialog_Title"),
       Util.getString("CTL_SelectPropDO_Dialog_RootTitle"),
       root,
       new NodeAcceptor() {
     public boolean acceptNodes(Node[] nodes) {
       if(nodes == null || nodes.length != 1) {
         return false;
       }

       // Has to be data object.
       DataObject dataObject = nodes[0].getCookie(DataObject.class);
       if(dataObject == null)
         return false;

       // Has to be of resource class.
       return dataObject.getClass().equals(PropertiesDataObject.class); // PENDING same like above.
     }
       }
       );
     return selectedNodes[0].getCookie(DataObject.class);
   } catch (UserCancelException uce) {
       //ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, uce);
           // nobody is interested in the message
       return null;
   }

 }
项目:incubator-netbeans    文件:GenerateDTDSupport.java   
/**
 * Performs a dialog with a user and generates the DTD
 */
public void generate() {

    try {
        //save the XML document before DTD generation
        SaveCookie save = (SaveCookie)template.getCookie(SaveCookie.class);
        if (save!=null) save.save();

        FileObject primFile = template.getPrimaryFile();
        String name = primFile.getName();
        FileObject folder = primFile.getParent();

        //use same name as the XML for default DTD name
        FileObject generFile = (new SelectFileDialog(folder, name, DTD_EXT, Util.NONEMPTY_CHECK)).getFileObject();

        //new name as per user
        name = generFile.getName();

        // get project's encoding
        String encoding = EncodingUtil.getProjectEncoding(primFile);

        //generate DTD content
        generateDTDContent(encoding, name, generFile);

        GuiUtil.performDefaultAction(generFile);

    } catch (UserCancelException e) {
    } catch (Exception exc) {
        GuiUtil.notifyException(exc);
    }
}
项目:studio    文件:PasteAction.java   
/** Does the execution of a paste type with all handling around
 */
private static void executePasteType (PasteType t) {
    NodeSelector sel = null;
    try {
        ExplorerManager em = findExplorerManager ();
        if (em != null) {
            sel = new NodeSelector (em, null);
        }

        Transferable trans = t.paste();
        Clipboard clipboard = getClipboard();


        if (trans != null) {
            ClipboardOwner owner = trans instanceof ClipboardOwner ?
                                   (ClipboardOwner)trans
                                   :
                                   new StringSelection (""); // NOI18N
            clipboard.setContents(trans, owner);
        }
    } catch (UserCancelException exc) {
        // ignore - user just pressed cancel in some dialog....
    } catch (java.io.IOException e) {
        ErrorManager.getDefault().notify(e);
    } finally {
        if (sel != null) {
            sel.select ();
        }
    }
}
项目:incubator-netbeans    文件:DragDropUtilities.java   
/**
 * Performs the drop. Performs paste on given paste type.
 * (part of bugfix #37279, performPaste returns array of new nodes in target folder)
 * @param type paste type
 * @param targetFolder target folder for given paste type, can be null
 * @return array of new added nodes in target folder
 */
static Node[] performPaste(PasteType type, Node targetFolder) {
    //System.out.println("performing drop...."+type); // NOI18N
    try {
        if (targetFolder == null) {
            // call paste action
            type.paste();

            return new Node[] {  };
        }

        Node[] preNodes = targetFolder.getChildren().getNodes(true);

        // call paste action
        type.paste();

        Node[] postNodes = targetFolder.getChildren().getNodes(true);

        // calculate new nodes
        List<Node> pre = Arrays.asList(preNodes);
        List<Node> post = Arrays.asList(postNodes);
        Iterator<Node> it = post.iterator();
        List<Node> diff = new ArrayList<Node>();

        while (it.hasNext()) {
            Node n = it.next();

            if (!pre.contains(n)) {
                diff.add(n);
            }
        }

        return diff.toArray(new Node[diff.size()]);

        /*Clipboard clipboard = T opManager.getDefault().getClipboard();
        if (trans != null) {
          ClipboardOwner owner = trans instanceof ClipboardOwner ?
            (ClipboardOwner)trans
          :
            new StringSelection ("");
          clipboard.setContents(trans, owner);
        }*/
    } catch (UserCancelException exc) {
        // ignore - user just pressed cancel in some dialog....
        return new Node[] {  };
    } catch (IOException e) {
        Exceptions.printStackTrace(e);

        return new Node[] {  };
    }
}
项目:incubator-netbeans    文件:CloneableEditorSupport.java   
/** Should test whether all data is saved, and if not, prompt the user
 * to save.
 *
 * @return <code>true</code> if everything can be closed
 */
 @Override
 protected boolean canClose() {
     if (cesEnv().isModified()) {

class SafeAWTAccess implements Runnable {
    boolean running;
    boolean finished;
    int ret;

    public void run() {
        synchronized (this) {
            running = true;
            notifyAll();
        }

        try {
            ret = canCloseImpl();
        } finally {                 
            synchronized (this) {
                finished = true;
                notifyAll();
            }
        }
    }



    public synchronized void waitForResult() throws InterruptedException {
        if (!running) {
            wait(10000);
        }
        if (!running) {
            throw new InterruptedException("Waiting 10s for AWT and nothing! Exiting to prevent deadlock"); // NOI18N
        }

        while (!finished) {
            wait();
        }
    }
}


SafeAWTAccess safe = new SafeAWTAccess();
         if (SwingUtilities.isEventDispatchThread()) {
             safe.run(); 
         } else {
             SwingUtilities.invokeLater(safe); 
             try {
                 safe.waitForResult();
             } catch (InterruptedException ex) {
                 ERR.log(Level.INFO, null, ex);
                 return false;
             }
         }

         if (safe.ret == 0) {
             return false;
         }

         if (safe.ret == 1) {
             try {
                 saveDocument();
             } catch (UserCancelException uce) {
                 return false;
             } catch (IOException e) {
                 Exceptions.printStackTrace(e);

                 return false;
             }
         }
     }

     return true;
 }
项目:incubator-netbeans    文件:CloneableEditorSupportPaneTest.java   
@Override
public void saveDocument() throws IOException {
    throw new UserCancelException();
}
项目:incubator-netbeans    文件:OpenProjectCLITest.java   
public Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top) throws UserCancelException {
    fail("no select");
    return null;
}
项目:incubator-netbeans    文件:OpenFileAction.java   
/**
 * {@inheritDoc} Displays a file chooser dialog
 * and opens the selected files.
 */
@Override
public void actionPerformed(ActionEvent e) {
    if (running) {
        return;
    }
    try {
        running = true;
        JFileChooser chooser = prepareFileChooser();
        File[] files;
        try {
            if( Boolean.getBoolean("nb.native.filechooser") ) { //NOI18N
                String oldFileDialogProp = System.getProperty("apple.awt.fileDialogForDirectories"); //NOI18N
                System.setProperty("apple.awt.fileDialogForDirectories", "false"); //NOI18N
                FileDialog fileDialog = new FileDialog(WindowManager.getDefault().getMainWindow());
                fileDialog.setMode(FileDialog.LOAD);
                fileDialog.setDirectory(getCurrentDirectory().getAbsolutePath());
                fileDialog.setTitle(chooser.getDialogTitle());
                fileDialog.setVisible(true);
                if( null != oldFileDialogProp ) {
                    System.setProperty("apple.awt.fileDialogForDirectories", oldFileDialogProp); //NOI18N
                } else {
                    System.clearProperty("apple.awt.fileDialogForDirectories"); //NOI18N
                }

                if( fileDialog.getDirectory() != null && fileDialog.getFile() != null ) {
                    String selFile = fileDialog.getFile();
                    File dir = new File( fileDialog.getDirectory() );
                    files = new File[] { new File( dir, selFile ) };
                    currentDirectory = dir;
                } else {
                    throw new UserCancelException();
                }
            } else {
                files = chooseFilesToOpen(chooser);
                currentDirectory = chooser.getCurrentDirectory();
                if (chooser.getFileFilter() != null) { // #227187
                    currentFileFilter =
                            chooser.getFileFilter().getDescription();
                }
            }
        } catch (UserCancelException ex) {
            return;
        }
        for (int i = 0; i < files.length; i++) {
            OpenFile.openFile(files[i], -1);
        }
    } finally {
        running = false;
    }
}
项目:incubator-netbeans    文件:OpenCLITest.java   
@Override
public Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top) throws UserCancelException {
    fail("no select");
    return null;
}
项目:incubator-netbeans    文件:SelectorUtils.java   
/** Instantiate a template object.
 * Asks user for the target file's folder and creates the file.
 * @param project the project the template should be instantiated in
 * @param refFile the file for which bundle is created 
 * @param template the template to use
 * @return the generated DataObject
 * @exception UserCancelException if the user cancels the action
 * @exception IOException on I/O error
 * @see DataObject#createFromTemplate
 */
public static DataObject instantiateTemplate(Project project, FileObject refFile, DataObject template) throws IOException {
  // Create component for for file name input.
  ObjectNameInputPanel panel = new ObjectNameInputPanel();

  Node repositoryNode =  SelectorUtils.bundlesNode(project, refFile, false);

  // Selects one folder from data systems.
  DataFolder dataFolder = 
    NodeOperation.getDefault().select
    (
     I18nUtil.getBundle().getString ("CTL_Template_Dialog_Title"),
     I18nUtil.getBundle().getString ("CTL_Template_Dialog_RootTitle"),
     repositoryNode,
     new NodeAcceptor() {
public boolean acceptNodes(Node[] nodes) {
  if(nodes == null || nodes.length != 1) {
    return false;
  }

  DataFolder cookie = nodes[0].getCookie(DataFolder.class);
  return (cookie != null && cookie.getPrimaryFile().canWrite());
}
     },
     panel
     )[0].getCookie(DataFolder.class);

     String name = panel.getText();

     DataObject newObject;

     if(name.equals ("")) { // NOI18N
newObject = template.createFromTemplate(dataFolder);
     } else {
newObject = template.createFromTemplate(dataFolder, name);
     }

     try {
return newObject;
     } catch(ClassCastException cce) {
throw new UserCancelException();
     }
}
项目:incubator-netbeans    文件:NodeOperationImpl.java   
/** Opens explorer for specified root in modal mode. The set
* of selected components is returned as a result. The acceptor
* should be asked each time selected nodes changes to accept or
* reject the current result. This should affect for example the
* <EM>OK</EM> button.
*
* @param title is a title that will be displayed as a title of the window
* @param root the root to explore
* @param acceptor the class that is asked for accepting or rejecting
*    current selection
* @param top is a component that will be displayed on the top
* @return array of selected (and accepted) nodes
*
* @exception UserCancelException selection interrupted by user
*/
public Node[] select (String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top)
throws UserCancelException {
    final FileSelector selector = new FileSelector(rootTitle, root, acceptor, top);
    selector.setBorder(new EmptyBorder(12, 12, 0, 12));
    DialogDescriptor dd = new DialogDescriptor(selector, title, true, 
                                               selector.getOptions(), 
                                               selector.getSelectOption(), DialogDescriptor.DEFAULT_ALIGN,
                                               HelpCtx.DEFAULT_HELP, null);
    Object ret = DialogDisplayer.getDefault().notify(dd);
    if (ret != selector.getSelectOption()) {
        throw new UserCancelException ();
    }
    return selector.getNodes ();
}
项目:studio    文件:NodeOperation.java   
/** Open a modal Explorer accepting only a single node.
 * @param title title of the dialog
 * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
 * @param root root node to explore
 * @return the selected node
 *
 * @exception UserCancelException if the selection is interrupted by the user
 * @see #select(String, String, Node, NodeAcceptor)
 */
public final Node select(String title, String rootTitle, Node root) throws UserCancelException {
    return select(title, rootTitle, root, new NodeAcceptor() {
        public boolean acceptNodes(Node[] nodes) {
            return nodes.length == 1;
        }
    })[0];
}
项目:incubator-netbeans    文件:NodeOperation.java   
/** Open a modal Explorer on a root node, permitting a node selection to be returned.
 * <p>The acceptor
 * should be asked each time the set of selected nodes changes, whether to accept or
 * reject the current result. This will affect for example the
 * display of the "OK" button.
 *
 * @param title title of the dialog
 * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
 * @param root root node to explore
 * @param acceptor class asked to accept or reject current selection
 * @param top an extra component to be placed on the dialog (may be <code>null</code>)
 * @return an array of selected (and accepted) nodes
 *
 * @exception UserCancelException if the selection is interrupted by the user
 */
public abstract Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top)
throws UserCancelException;
项目:incubator-netbeans    文件:NodeOperation.java   
/** Open a modal Explorer without any extra dialog component.
 * @param title title of the dialog
 * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
 * @param root root node to explore
 * @param acceptor class asked to accept or reject current selection
 * @return an array of selected (and accepted) nodes
 *
 * @exception UserCancelException if the selection is interrupted by the user
 * @see #select(String, String, Node, NodeAcceptor, Component)
 */
public Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor)
throws UserCancelException {
    return select(title, rootTitle, root, acceptor, null);
}
项目:studio    文件:NodeOperation.java   
/** Open a modal Explorer on a root node, permitting a node selection to be returned.
 * <p>The acceptor
 * should be asked each time the set of selected nodes changes, whether to accept or
 * reject the current result. This will affect for example the
 * display of the "OK" button.
 *
 * @param title title of the dialog
 * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
 * @param root root node to explore
 * @param acceptor class asked to accept or reject current selection
 * @param top an extra component to be placed on the dialog (may be <code>null</code>)
 * @return an array of selected (and accepted) nodes
 *
 * @exception UserCancelException if the selection is interrupted by the user
 */
public abstract Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top)
    throws UserCancelException;
项目:studio    文件:NodeOperation.java   
/** Open a modal Explorer without any extra dialog component.
 * @param title title of the dialog
 * @param rootTitle label at root of dialog. May use <code>&amp;</code> for a {@link javax.swing.JLabel#setDisplayedMnemonic(int) mnemonic}.
 * @param root root node to explore
 * @param acceptor class asked to accept or reject current selection
 * @return an array of selected (and accepted) nodes
 *
 * @exception UserCancelException if the selection is interrupted by the user
 * @see #select(String, String, Node, NodeAcceptor, Component)
 */
public Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor)
    throws UserCancelException  {
    return select(title, rootTitle, root, acceptor, null);
}