Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Corona HowTo: Add a new page to Project Container View"

(An example)
(obsolete)
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''UNDER CONSTRUCTION'''
 
  
The [[Corona Project Container View|Project Container View (PCV)]] can be easily extended to contain new pages. Even the default pages are added by extension mechanism.
 
 
First thing to note is that there are two kinds of pages:
 
* per project container
 
* per repository
 
 
The ''per project container'' pages displays information that are not connected with any repository, but rather with project container itself. This pages are displayed for every project container, no matter what it contains. The ''per repository'' pages in contrast show information defined in a repository. This kind of page is displayed only if the page matches a repository defined in the project container.
 
 
The later sections shows step-by-step how to add your own PCV page.
 
 
== Define extension ==
 
Firstly you need to provide an extension to Corona PCV page extension point. This step is required no matter if you provide a ''per project container'' or ''per repository'' page. To achieve it, do fallowing:
 
# Open plugin.xml editor.
 
# Switch to ''Dependencies'' tab.
 
# Add ''org.eclipse.corona.container.project.ui'' to ''required plug-ins''.
 
# Switch to ''Extensions'' tab.
 
# Click the ''Add'' button and select ''org.eclipse.corona.container.project.ui.page'' and click ''Finish''
 
 
Save changes to the plugin.xml. This point will be taken as start point for both adding ''per project container'' and ''per repository'' page.
 
 
== Common interfaces for pages ==
 
Both types of pages are in fact extended Eclipse view. They implement a specialized interfaces which are in fact extension of three basic Eclipse interfaces:
 
* [http://help.eclipse.org/help31/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/IViewPart.html ''org.eclipse.ui.'''IViewPart'''''] is default for Eclipse to create views.
 
* [http://help.eclipse.org/help31/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/runtime/IExecutableExtension.html ''org.eclipse.core.runtime.'''IExecutableExtension'''''], which is used to provide extension point element that was used to create instance.
 
* [http://bundles.osgi.org/javadoc/r4/org/osgi/service/event/EventHandler.html ''org.osgi.service.event.'''EventHandler'''''] used to deliver [[Corona Design Collaboration|collaboration events]] that take place in the project container for which the page was created. You do not need to register/unregister yourself for events - it will be done for you.
 
 
The class must also provide a default public constructor. For both classes there are abstract default implementations that provide default implementations to most methods.
 
 
== Per project container page ==
 
You have plugin.xml editor opened on ''Extensions'' tab. Now, we need to create the page. So do fallowing:
 
# Right-click ''org.eclipse.corona.container.project.ui.page'' in ''All Extensions'' list.
 
# Select ''New -> projectPage'' from the pop-up menu.
 
# On the right side in ''Extension Element Details'' fill the page information:
 
#* 'id' - the unique identifier of the page within the Eclipse installation. It should be prefixed with our plugin name to ensure uniqueness.
 
#* 'name' - the name of the page, which will be displayed in the page tab; used for UI only.
 
#* 'class' - the full qualified name of class that implement the page; the class must implement ''org.eclipse.corona.container.project.ui.view.page.'''IProjectContainerPage''''' interface.
 
# Save changes in plugin.xml.
 
# Implement the page view class.
 
 
The page class ''org.eclipse.corona.container.project.ui.view.page.'''IProjectContainerPage''''' interface, which contains interfaces described in [[#Common interfaces for pages|previous section]] plus provides a new init method that is used to provide the project container which is the subject of the page.
 
 
For your convenience we provided also an abstract class which provides default implementations of methods - ''org.eclipse.corona.container.project.ui.view.page.'''AbstractProjectContainerPage'''''. Unless you have your inheritance structure, you should probably use it instead of implementing ''IProjectContainerPage'' from scratch.
 
 
=== An example ===
 
Lets create a simple page that simply shows a a name of project container as it content. So firstly you need to define the extension as described earlier. It would look as at the image below.
 
 
[[Image:Corona howto namepage1.png]]
 
 
The corresponding plugin.xml fragment looks like this:
 
 
  <extension
 
        point="org.eclipse.corona.container.project.ui.page">
 
      <projectPage
 
            class="org.eclipse.corona.examples.pcv.page.ProjectNamePage"
 
            id="org.eclipse.corona.examples.pcv.page.projectNamePage"
 
            name="Project Name"/>
 
  </extension>
 
 
Now it is time to implement the view class. To make our live easier I will use adapter. Note that the project context container is already set as a field and is ready to use. The default abstract class implementation saves the project context in a field.
 
 
package org.eclipse.corona.examples.pcv.page;
 
 
import org.eclipse.corona.container.project.ui.view.page.AbstractProjectContainerPage;
 
import org.eclipse.corona.container.project.ui.view.page.IProjectContainerPage;
 
import org.eclipse.swt.SWT;
 
import org.eclipse.swt.widgets.Composite;
 
import org.eclipse.swt.widgets.Label;
 
 
public class ProjectNamePage extends AbstractProjectContainerPage
 
                              implements IProjectContainerPage {
 
 
public void createPartControl(Composite parent) {
 
Label projectName = new Label(parent, SWT.NONE);
 
projectName.setText("Name: " + this.container.getName());
 
}
 
}
 
 
The result of this example is as at the picture below.
 
 
[[Image:Corona howto namepage2.png]]
 
 
Simple, isn't it? :)
 

Latest revision as of 10:49, 27 February 2008

Back to the top