Linking drop down lists with files - java

How do I link the drop down lists with files in hard disk, so that on selecting an option in drop down list (which is actually a folder in one of the drive of the hard disk) must get selected and it must display the files present in the folder in the same list?

I think what you need is a JFileChooser. You can find a tutorial on how to use it here.

You should get the directories you want to show (java.io.File instances) and use these directories as the items of the combo box. Then add an action listener of this combo box. This listener will be called each time the user selects one of the directories in the combo box. Then just ask the combo box its selected item, and list the files of the selected directory.
You may customize how the directories are displayed inside the combo box using a ListCellRenderer.
I suggest you read the Swing tutorial, where all this is well explained.

Related

How do i maintain order of selected files in javafx multi file chooser

I'm trying to implement a multiple file selection feature in my program where the order a user selects these files really matters.
Currently what I'm doing is storing the selected files in a list of files so as to loop through and process them individually, however, the files get sorted by default in ascending order. Is there a way to go about this?

PDF Viewer in JavaFX

I am using JavaFx-2.I need to view the pdf file in JavaFx. I searched in Google and found the below link.
http://www.idrsolutions.com/jpedalfx-viewer/
In this link I have created every thing whatever mentioned there and I am able to see PdfHelpPanel in Palette. When I drag this component to the PDFHelpFrame I am able to see the fileLocations property. Here I need to give the file locations but I don't know how to give the location of my pdf file. When I click browse in filelocations property it is asking for Custom Code, Default Editor, value from existing component. Which one I need to select. I am struck up exactly at
http://netbeans.dzone.com/articles/how-create-import-a-javabean-c-0
second image from last. If any one has done this already can you help me?
You can use this project https://github.com/james-d/PdfViewer
It uses PDFRenderer library.

Showing the most recent opened items in a menu bar

I want to create a window with Java Swing. The window will have a menu bar with a File->Open button from where the user can select a file from hid hard drive. The File menu should also have a list of the most recent opened items, like many other applications show. Does anyone know what is the best approach?
I would suggest using the Preferences class to persist the most recently opened items. That way, if the user restarts the application the items will still be available.
Note that on Windows the Preferences class stores data in the registry, which is how many native Windows applications store and retrieve recently open file names.
Also, note that the Preferences class simply acts as an API for storing and retrieving (key, value) pairs. You will still need to decide how you wish to store the information, and be responsible for dynamically building / updating the JMenu when a new file is accessed. To accomplish this I would suggest implementing a Action (extend AbstractAction) to deal with when the user attempts to open a file. When the Action runs it should persist the newly accessed file's name to the Preferences class and dynamically rebuild the File JMenu (in addition to opening the file).

How to write an editor that shows the content of a folder in eclipse?

Motivation
I have written an eclipse plugin that shows me a list of all files and folders with unreviewed content. When selecting a folder, I want an editor to open showing all files and subfolders that this folder contains. It has to work for versioned items, too. So I have to create the content of the editor within my plugin (no backing IResource).
What I currently have
Right now I'm opening a RemoteFileEditorInput for a versioned file (subclipse) or I'm using IWorkbenchPage.openEditor() for a FileEditorInput.
Question
What's an easy way to visualize dynamic content (directory listing) inside of an text editor?
EDIT 2010-04-13:
More Context
I want to be able to create some code review comments on a directory listing. For this I want to be able to open a diff viewer to see which elements were removed or added between two revisions of the directory.
I'd like to enter a comment for a directory the same way I do for a text file. That's why I try to display the directory content as a text file - I've already implemented the mechanisms for commenting a text file.
I call the content of the directory editor "dynamic", because it's not really backed by an existing directory in the filesystem. For older versions of a directory I will create the editor content within my program code.
I'm afraid I don't totally understand your question (and I lack the rep to comment on it).
Is this right?: You want to be able to open one of three editors in support of your goal:
An editor for unversioned files (you say you have this)
An editor for versioned files (you say you have this)
An editor for directories (this is what you need?)
What does the user do here? What does it look like?
I'm confused by "What's an easy way to visualize dynamic content (directory listing) inside of an text editor?"
Knowing that I probably completely miss your point, I would note that your editor can contain whatever controls you want it to (cf. some of the "forms" editors in PDE, like for editing a plug-in manifest) - you'd probably extend EditorPart, maybe create a ManagedForm in your createPartControl(), create a ListViewer, TableViewer, or TreeViewer in there, give it an appropriate content provider, and give it an appropriate label provider.
I'm also confused by "What's an easy way to visualize dynamic content (directory listing) inside of an text editor?"
I can only assume that you want to somehow poll or listen to some events and tell your viewer to update() or refresh().
Finally I would question whether the directory listing really belongs in an editor . . . most navigation happens in views. Will the user actually be performing edits to the directory somehow, and possibly "saving" them at some later time?
I hope this helps us all narrow down into whatever will help you.

Changing pop-ups dynamically in eclipse plugin

I have a plugin where for a particular type of file i will enable some options to perform. so now i have requirement where i need to decide the type of a file dynamically and apply a particular options for that type of file.
Is it possible to do that? if yes, need some help about the same.
Thanks.
So I guess you want to show the context menu for something that represents a file in a view. Determine the file type based on custom rules (file extension is the easiest rule, looking inside the file the most complex) and create the popup or distribute content to an existing one.
If it's your own view, maybe a list or tree that shows a folder structure, then you have to register the Viewer as a SelectionProvider, listen to selection events, evaluate the selection (maybe a String or a File object) and create the popup menu.
Contributing actions to existing popup menus (like the navigator view context menus) is possible as well but a bit more challenging.

Categories