Java Code Examples for org.openide.util.UserCancelException

The following examples show how to use org.openide.util.UserCancelException. These examples are extracted from open source projects. 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 Project: constellation   Source File: OpenFileAction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc} Displays a file chooser dialog and opens the selected
 * files.
 */
@Override
public void actionPerformed(final ActionEvent e) {
    if (running) {
        return;
    }
    try {
        running = true;
        JFileChooser chooser = prepareFileChooser();
        File[] files;
        try {
            files = chooseFilesToOpen(chooser);
            currentDirectory = chooser.getCurrentDirectory();
        } catch (UserCancelException ex) {
            return;
        }
        for (int i = 0; i < files.length; i++) {
            OpenFile.openFile(files[i], -1);
        }
    } finally {
        running = false;
    }
}
 
Example 2
Source Project: netbeans   Source File: NodeOperationImpl.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source Project: netbeans   Source File: PasteAction.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
Source Project: netbeans   Source File: BaseJspEditorSupport.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected boolean notifyModified() {
    boolean notify = super.notifyModified();
    if (!notify) {
        return false;
    }
    JspDataObject obj = (JspDataObject) getDataObject();
    if (obj.getCookie(SaveCookie.class) == null) {
        obj.addSaveCookie(new SaveCookie() {

            public void save() throws java.io.IOException {
                try {
                    saveDocument();
                } catch (UserCancelException e) {
                    //just ignore
                }
            }
        });
    }
    return true;
}
 
Example 5
Source Project: netbeans   Source File: TplDataObject.java    License: Apache License 2.0 6 votes vote down vote up
public TplDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
    super(pf, loader);
    CookieSet set = getCookieSet();
    set.add(TplEditorSupport.class, this);
    set.assign(SaveAsCapable.class, new SaveAsCapable() {

        @Override
        public void saveAs(FileObject folder, String fileName) throws IOException {
            TplEditorSupport es = getLookup().lookup(TplEditorSupport.class);
            try {
                es.updateEncoding();
                es.saveAs(folder, fileName);
            } catch (UserCancelException e) {
                //ignore, just not save anything
            }
        }
    });

    set.assign(FileEncodingQueryImplementation.class, new FileEncodingQueryImpl());
}
 
Example 6
Source Project: netbeans   Source File: HtmlDataObject.java    License: Apache License 2.0 6 votes vote down vote up
/** 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));
    
}
 
Example 7
Source Project: constellation   Source File: OpenFileAction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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(final 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;
}
 
Example 8
Source Project: netbeans   Source File: SelectorUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
  * 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;
   }

 }
 
Example 9
Source Project: netbeans   Source File: NodeOperation.java    License: Apache License 2.0 5 votes vote down vote up
/** 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];
}
 
Example 10
Source Project: netbeans   Source File: AddModuleAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void performAction(Node[] activeNodes) {
    try {
        Project p = activeNodes[0].getLookup().lookup(Project.class);
        Project[] moduleProjects = getSelectedProjects(p.getProjectDirectory());
        // XXX Vince add code here to add to application.xml and
        // build script
        EarProject ep = p.getLookup().lookup(EarProject.class);
        EarProjectProperties.addJ2eeSubprojects(ep, moduleProjects);
    } catch (UserCancelException uce) {
        // this action has been cancelled
    }
}
 
Example 11
Source Project: netbeans   Source File: TplEditorSupport.java    License: Apache License 2.0 5 votes vote down vote up
/** Implements <code>SaveCookie</code> interface. */
@Override
public void save() throws IOException {
    try {
        saveDocument();
    } catch (UserCancelException uce) {
        //just ignore
    }
}
 
Example 12
Source Project: netbeans   Source File: HtmlEditorSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Implements
 * <code>SaveCookie</code> interface.
 */
@Override
public void save() throws IOException {
    try {
        saveDocument();
    } catch (UserCancelException uce) {
        //just ignore
    }
}
 
Example 13
Source Project: netbeans   Source File: OpenFileAction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source Project: netbeans   Source File: GenerateDTDSupport.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 15
Source Project: netbeans   Source File: SelectorUtils.java    License: Apache License 2.0 4 votes vote down vote up
/** 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();
     }
}
 
Example 16
Source Project: netbeans   Source File: DragDropUtilities.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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[] {  };
    }
}
 
Example 17
Source Project: netbeans   Source File: CloneableEditorSupport.java    License: Apache License 2.0 4 votes vote down vote up
/** 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;
 }
 
Example 18
Source Project: netbeans   Source File: CloneableEditorSupportPaneTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void saveDocument() throws IOException {
    throw new UserCancelException();
}
 
Example 19
Source Project: netbeans   Source File: AddModuleAction.java    License: Apache License 2.0 4 votes vote down vote up
private Project[] getSelectedProjects(FileObject projDir) throws UserCancelException {
    Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
    List<Node> moduleProjectNodes = new LinkedList<Node>();
    for (int i = 0; i < allProjects.length; i++) {
        if (EarProjectUtil.isJavaEEModule(allProjects[i])) {
            LogicalViewProvider lvp = allProjects[i].getLookup().lookup(LogicalViewProvider.class);
            Node mn = lvp.createLogicalView();
            Node n = new FilterNode(mn, new FilterNode.Children(mn), Lookups.singleton(allProjects[i]));
            moduleProjectNodes.add(n);
        }
    }
    Children.Array children = new Children.Array();
    children.add(moduleProjectNodes.toArray(new Node[moduleProjectNodes.size()]));
    final AbstractNode root = new AbstractNode(children);
    String moduleSelector = NbBundle.getMessage(AddModuleAction.class, "LBL_ModuleSelectorTitle");
    
    Project parent = FileOwnerQuery.getOwner(projDir);
    SubprojectProvider spp = parent.getLookup().lookup(SubprojectProvider.class);
    if (null != spp) {
        final Set s = spp.getSubprojects();
        NodeAcceptor na = new NodeAcceptor() {
            public boolean acceptNodes(Node[] nodes) {
                for (int i = 0; i < nodes.length; i++) {
                    if (nodes[i].getParentNode() != root) {
                        return false;
                    }
                    // do not put this test befor the root test...
                    Project p = nodes[i].getLookup().lookup(Project.class);
                    if (null == p) {
                        return false;
                    }
                    if (s.contains(p)) {
                        return false;
                    }
                }
                return nodes.length > 0;
            }
        };
        root.setDisplayName(NbBundle.getMessage(AddModuleAction.class, "LBL_J2EEModules"));
        root.setIconBaseWithExtension(FOLDER_ICON);
        Node[] selected = NodeOperation.getDefault().select(moduleSelector, root.getDisplayName(), root, na);
        Project[] modules = new Project[selected.length];
        for (int i = 0; i < modules.length; i++) {
            modules[i] = selected[i].getLookup().lookup(Project.class);
        }
        return modules;
  }
    else {
        return new Project[0];
    }
}
 
Example 20
Source Project: netbeans   Source File: TplEditorSupport.java    License: Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages({
    "warning=Warning",
    "# {0} document name",
    "# {1} encoding",
    "# {2} original encoding of the file when loaded",
    "MSG_unsupportedEncodingSave=<html>The encoding {1} specified in meta tag of the document {0} is invalid<br> or the document contains characters which cannot be saved using this encoding.<br> Do you want to save the file using <b>{2}</b> encoding?</html>"
})
void updateEncoding() throws UserCancelException {
    //try to find encoding specification in the editor content
    String documentContent = getDocumentText();
    String encoding = TplDataObject.findEncoding(documentContent);
    String feqEncoding = FileEncodingQuery.getEncoding(getDataObject().getPrimaryFile()).name();
    String finalEncoding = null;
    if (encoding != null) {
        //found encoding specified in the file content by meta tag
        if (!isSupportedEncoding(encoding) || !canEncode(documentContent, encoding)) {
            //test if the file can be saved by the original encoding or if it needs to be saved using utf-8
            finalEncoding = canEncode(documentContent, feqEncoding) ? feqEncoding : UTF_8_ENCODING;
            Integer showEncodingWarnings = getTplDO().getShowEncodingWarnings();
            if (showEncodingWarnings == null) {
                String message = MSG_unsupportedEncodingSave(getDataObject().getPrimaryFile().getNameExt(), encoding, finalEncoding); 
                SaveConfirmationPanel panel = new SaveConfirmationPanel(message);
                DialogDescriptor dd = new DialogDescriptor(panel, Bundle.warning(), true, DialogDescriptor.YES_NO_OPTION, DialogDescriptor.YES_OPTION, null);
                DialogDisplayer.getDefault().notify(dd);
                showEncodingWarnings = (Integer) dd.getValue();
                if (panel.isDoNotShowAgainCheckBox() && showEncodingWarnings == NotifyDescriptor.YES_OPTION) {
                    getTplDO().setShowEncodingWarnings(showEncodingWarnings);
                }
            }
            if (!showEncodingWarnings.equals(NotifyDescriptor.YES_OPTION)) {
                throw new UserCancelException();
            }
        } else {
            finalEncoding = encoding;
        }
    } else {
        //no encoding specified in the file, use FEQ value
        if (!canEncode(documentContent, feqEncoding)) {
            NotifyDescriptor nd = new NotifyDescriptor.Confirmation(NbBundle.getMessage(TplEditorSupport.class, "MSG_badCharConversionSave", new Object[]{getDataObject().getPrimaryFile().getNameExt(), feqEncoding}), NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE);
            nd.setValue(NotifyDescriptor.NO_OPTION);
            DialogDisplayer.getDefault().notify(nd);
            if (nd.getValue() != NotifyDescriptor.YES_OPTION) {
                throw new UserCancelException();
            } else {
                finalEncoding = UTF_8_ENCODING;
            }
        } else {
            finalEncoding = feqEncoding;
        }
    }

    //FEQ cannot be run in saveFromKitToStream since document is locked for writing,
    //so setting the FEQ result to document property
    Document document = getDocument();
    if (document != null) {
        document.putProperty(DOCUMENT_SAVE_ENCODING, finalEncoding);
    }
}
 
Example 21
Source Project: netbeans   Source File: OpenProjectCLITest.java    License: Apache License 2.0 4 votes vote down vote up
public Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top) throws UserCancelException {
    fail("no select");
    return null;
}
 
Example 22
Source Project: netbeans   Source File: OpenFileAction.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * {@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;
    }
}
 
Example 23
Source Project: netbeans   Source File: OpenCLITest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Node[] select(String title, String rootTitle, Node root, NodeAcceptor acceptor, Component top) throws UserCancelException {
    fail("no select");
    return null;
}
 
Example 24
Source Project: visualvm   Source File: AcceptLicense.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * If License was not accepted during installation user must accept it here.
 */
public static void showLicensePanel() throws Exception {
    Utils.setSystemLaF();

    // Make sure the code following this call runs on JDK 6
    if (!VisualVMStartup.checkEnv())
        throw new org.openide.util.UserCancelException();

    URL url = AcceptLicense.class.getResource("LICENSE.txt"); // NOI18N
    LicensePanel licensePanel = new LicensePanel(url);
    ResourceBundle bundle = NbBundle.getBundle(AcceptLicense.class);
    String yesLabel = bundle.getString("MSG_LicenseYesButton"); // NOI18N
    String noLabel = bundle.getString("MSG_LicenseNoButton"); // NOI18N
    JButton yesButton = new JButton();
    JButton noButton = new JButton();
    Utils.setLocalizedText(yesButton, yesLabel);
    Utils.setLocalizedText(noButton, noLabel);
    ActionListener listener = new ActionListener () {
        public void actionPerformed(ActionEvent e) {
            command = e.getActionCommand();
            d.setVisible(false);
            d.dispose();
            d = null;
        }            
    };
    yesButton.addActionListener(listener);
    noButton.addActionListener(listener);
    
    yesButton.setActionCommand(YES_AC);
    noButton.setActionCommand(NO_AC);
    
    yesButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_AcceptButton")); // NOI18N
    yesButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSD_AcceptButton")); // NOI18N
    
    noButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_RejectButton")); // NOI18N
    noButton.getAccessibleContext().setAccessibleName(bundle.getString("ACSD_RejectButton")); // NOI18N
    
    Dimension yesPF = yesButton.getPreferredSize();
    Dimension noPF = noButton.getPreferredSize();
    int maxWidth = Math.max(yesPF.width, noPF.width);
    int maxHeight = Math.max(yesPF.height, noPF.height);
    yesButton.setPreferredSize(new Dimension(maxWidth, maxHeight));
    noButton.setPreferredSize(new Dimension(maxWidth, maxHeight));

    d = StartupDialog.create(bundle.getString("MSG_LicenseDlgTitle"), null, -1); // NOI18N
    
    d.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_LicenseDlg")); // NOI18N
    d.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_LicenseDlg")); // NOI18N
    
    d.getContentPane().add(licensePanel, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(17, 12, 11, 11));
    buttonPanel.add(yesButton);
    buttonPanel.add(noButton);
    d.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    d.setSize(new Dimension(600, 600));
    d.setResizable(true);
    d.setLocationRelativeTo(null);
    d.setVisible(true);
    
    if (!YES_AC.equals(command)) throw new UserCancelException();
}
 
Example 25
Source Project: netbeans   Source File: NodeOperationImpl.java    License: Apache License 2.0 3 votes vote down vote up
/** 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 ();
}
 
Example 26
Source Project: netbeans   Source File: NodeOperation.java    License: Apache License 2.0 2 votes vote down vote up
/** 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;
 
Example 27
Source Project: netbeans   Source File: NodeOperation.java    License: Apache License 2.0 2 votes vote down vote up
/** 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);
}