Eclipse

RCP Tips

_침묵_ 2005. 10. 20. 07:33

RCP Tips and TricksI'm wrapping up development on my first RCP application and thoughtI'd post some code and links I've found helpful during construction.

I am coming to SWT development after 5-6 years of Swing work.That being said, the ideas mentioned in the article may be way basic and knownby everyone else who uses RCP consistently. If this is a waste of Javalobby disk space, I apologize :) But for the any others out there who venture into RCPland, perhaps this page will prove useful.

Useful Links:
-Plug a Swing-based tool/plugin into Eclipse
-Pluthera of examples for SWT/JFace
-Eclipse Jobs API guide
-Eclipse Forms API guide

-Eclipse DataBinding Code (Test examples)
-Eclipse.org main page for SWT Resources


RCP Tip#1
Remove extra menubar/coolbar contributions


I needed to utilize the editor and IDE plugins, which unfortunately puts
extra actions in the menus - like 'Open External File'.
One solution I found was to remove the extra
contributions in the windowAdvisor:

        IMenuManager mm =
            getWindowConfigurer().getActionBarConfigurer().getMenuManager();
        IContributionItem[] mItems = mm.getItems();
        for (int i = 0; i < mItems.length; i++) {
            System.out.println(mItems[i].getId());
            if (mItems[i].getId().equals("navigate") ||
                    mItems[i].getId().equals("additions") ||  //marker
                    mItems[i].getId().equals("org.eclipse.search.menu")){//contribution
              mm.remove(mItems[i].getId());
              mm.update(true);
            }
        }

RCP Tip#2
Remove preferences you dont need

If your app is dependent on the IDE,editor, or other plugins (like Web Tools)
you more than likely will need to supress the Preference Pages:

PreferenceManager pm = window.getWorkbench( ).getPreferenceManager( );
pm.remove( "org.eclipse.help.ui.browsersPreferencePage" );

RCP Tip#3
Get the OS-specific directory of your plugin

I needed to do this as I access some style files (css,images, html)
that are packaged with the app.

Plugin.getDefault().getDescriptor().getInstallURL();
RCP Tip#4
Consider using Swing and SWT

Not really news, but you can embed Swing in SWT using the a SWT-Swing bridge class. You still can tell the difference - especially with text - even with Swing set to thenative LaF. Maybe now that Mustang's text rendering is betterintegration will look tighter in the future. The code below was taken from
here.

          GridLayout gridLayout = new GridLayout();          gridLayout.numColumns = 1;          parent.setLayout(gridLayout);     
          Composite c = toolkit.createComposite(            parent,SWT.FLAT| SWT.EMBEDDED);          td = new TableWrapData(TableWrapData.FILL, TableWrapData.TOP);          td.grabHorizontal = true; td.grabVertical = true;          //c.setSize(400,400);          c.setLayoutData(td);                    java.awt.Frame frame = SWT_AWT.new_Frame(c);                    Panel panel = new Panel(new BorderLayout()) {                public void update(java.awt.Graphics g) {                    // Do not erase the background                      paint(g);                }            };            frame.add(panel);                        JRootPane root = new JRootPane();            panel.add(root);            java.awt.Container contentPane = root.getContentPane();                        contentPane.setLayout(new BorderLayout());            contentPane.add(new SwingPagePropertyForm(),BorderLayout.CENTER);           


RCP Tip #5
Save window size between sessions

From within the WorkbenchAdvisor:

public void initialize(IWorkbenchConfigurer configurer) {        super.initialize(configurer);        configurer.setSaveAndRestore(true);}
RCP Tip #6
Congregating multiple instances of same view

If you need to open several windows of the same view (ala tabbed browsers), youcan put them in the same IFolderLayout using wildcards:

folder.addPlaceholder("viewId:*");
RCP Tip #7
Hide view tabs (and make views 'fixed')

Using IFolderLayout from within the Perspective implementation:

layout.setFixed(true);layout.addStandaloneView(View.ID, false, IPageLayout.TOP, 0.50f, editorArea);
RCP Tip #8
Dynamically hide/show the editor area

You can do this from a WorkBenchPage. If I was in a View implementation,
I would call the site, get the active page, and then set the editor to be
hidden/visible:

getSite().getPage().setEditorAreaVisible(true);
RCP Tip #9
Convert a IFile to java.io.File

Got this directly from the OpenExternalFileAction. One
caveat, its returns a JavaFileEditorInput object if the
java.io.File is external to the workspace.

    private IEditorInput createEditorInput(File file) {        IFile workspaceFile= getWorkspaceFile(file);        if (workspaceFile != null)            return new FileEditorInput(workspaceFile);        return new JavaFileEditorInput(file);    }    private IFile getWorkspaceFile(File file) {        IWorkspace workspace= ResourcesPlugin.getWorkspace();        IPath location= Path.fromOSString(file.getAbsolutePath());        IFile[] files= workspace.getRoot().findFilesForLocation(location);        files= filterNonExistentFiles(files);        if (files == null || files.length == 0)            return null;        if (files.length == 1)            return files[0];        return selectWorkspaceFile(files);    }

RCP Tip #10
Propagate event between views

This helpful tip from jarchitect shows how to make
views listen to events fired by other views. See
http://www.jarchitect.org/tech/rcp/tutorial4.html

A few other interesting bits:
-Can I export my RCP product using ant?

A suprising no (at least it cannot be done now)

No, only if you export as plugin it is possible to save the generated ant file.In case you export everything as an eclipse product you don't have this option.see http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg05580.html

-Branding the help system:
http://www.eclipse.org/newsportal/article.php?id=5939&group=eclipse.platform.rcp#5939

-Create the a new console in an RCP app:
http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg00199.html

'Eclipse' 카테고리의 다른 글

Eclipse - a tale of two VMs (and many classloaders)  (0) 2006.06.18
[펌] Ant란?  (0) 2005.03.06
[펌] ANT (하): Ant 무엇에 쓰는 물건인고?  (0) 2005.03.06