Posts Tagged ‘rcp’

How to get all files in a project eclipse RCP

August 15, 2013 Leave a comment

In this post, I show you a very simple problem that how you can get all the file when you have your own project resource which is named iProject. The solution is using method member() in IProject and IFolder. At the first time I use this method for just project resource, then i search for earch resource got, and i check if it is a file. That’s a wrong thought. So, you have to go through each folder and get its member again.
And, the below snippet is the solution:

public static void getAllFilesInProject(
        final IProject project,
        final List<IFile> lstFiles,
        final String fileExtension)
            if (project.exists())
                if (!project.isOpen())
                IResource[] resources = project.members(false);
                for (IResource resFo : resources)
                    if (resFo instanceof IFolder)
                        IResource[] resFiles = ((IFolder) resFo).members();
                        for (IResource resFi : resFiles)
                            IFile file = (IFile) resFi;
                            if (fileExtension.equals(file.getFileExtension()))
        catch (Exception e)
  "Can not find any " + fileExtension + " file in the project " + project.getName());

And you pass your list file predefined at other place, and got out the files you want.

Categories: Java Tags: , , ,

Create an command for opening editor from navigator

As you know, navigator view of an eclipse RCP application default allows you open an editor such a text editor. That is one of default editors, how about your own editor. Using command is one of the ways. By every step, we have:
I assume that I have an editor from the class FormEditor, at here we have its ID_EDITOR, besides I have also an Navigator with ID_NAVIGATOR
First, declare a command in extension points
In plugin.xml we declare:

            name="Open Editor">

Read more…

Categories: Java Tags: , , , , ,

How to customize the Tool bar Eclipse RCP

In a standard way, creating an eclipse RCP application have to include creating these files:

  • Activator
  • Application
  • WorkbenchWindowAdvisor
  • ActionBarAdvisor
  • WorkbenchAdvisor
  • As for me, you should hide all the default actions and commands.
    You can do that in the file WorkbenchWindowAdvisor which contains the postWindowOpen() function:

    public void postWindowOpen()
            final String[] removeActionSets = new String[] { "",
                "org.eclipse.ui.cheatsheets.actionSet", "org.eclipse.ui.actionSet.keyBindings",
                "org.eclipse.ui.edit.text.actionSet.navigation", "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
                "org.eclipse.ui.edit.text.actionSet.openExternalFile", "org.eclipse.ui.externaltools.ExternalToolsSet",
                "org.eclipse.ui.WorkingSetActionSet", "org.eclipse.update.ui.softwareUpdates",
                "org.eclipse.ui.actionSet.openFiles", "org.eclipse.mylyn.tasks.ui.navigation", };
            IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
            for (int i = 0; i < windows.length; ++i)
                IWorkbenchPage page = windows[i].getActivePage();
                if (page != null)
                    for (int j = 0; j < removeActionSets.length; j++)

    Read more…

    Categories: Java Tags: , , , ,

    How to make views communicate in Eclipse RCP

    In eclipse Rich Client Platform programming, some times you need to keep contact between views. How can we do that?
    After a couple of hours research, I found the way to make two views interact each other.
    There are a few articles on web, but I think they make us embarrassed.
    I will make it more shortly and clearly.
    We have two views: ViewA and ViewB.
    In this case: we assume that ViewB is the event sender, and ViewA is the rest one, the receiver.
    So now, what we have to do with each of them.
    we have to register the selection provider to the SelectionService of workbench. That simply we put this in the function createPartControl of ViewB: Read more…

    Categories: Java Tags: , , ,

    Bug when using DefferedContentProvider in TableViewer eclipse

    When create an eclipse RCP application, times you use TableViewer need a content provider. There are many type of provider you can use for your table such as:
    an implementation of ILazyContentProvider
    My favorite type is the last one, DefferedContentProvider.:D. But, at the first time I used it, it did work. And, i got stuck in this runtime bug:

    org.eclipse.core.runtime.AssertionFailedException: assertion failed: 
    	at org.eclipse.core.runtime.Assert.isTrue(
    	at org.eclipse.core.runtime.Assert.isTrue(
    	at org.eclipse.jface.viewers.deferred.DeferredContentProvider.inputChanged(
    	at org.eclipse.jface.viewers.ContentViewer.setInput(
    	at org.eclipse.jface.viewers.StructuredViewer.setInput(
    	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(
    	at org.eclipse.ui.internal.e4.compatibility.CompatibilityView.createPartControl(
    	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    	at java.lang.reflect.Method.invoke(

    the error occurs while using DefferedContentProvider for TableViewer. Read more…

    %d bloggers like this: