DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Data Engineering
  3. Data
  4. Perspective Layouts - Programmatic vs Declarative

Perspective Layouts - Programmatic vs Declarative

Patrick Paulin user avatar by
Patrick Paulin
·
Dec. 16, 08 · Interview
Like (0)
Save
Tweet
Share
9.27K Views

Join the DZone community and get the full member experience.

Join For Free

one issue that developers new to rcp face is whether to add ui elements programmatically or declaratively. in my experience, most initially choose the programmatic approach because it seems more familiar. you know, why mess with extension points when you can just code it up and be done with it.

but it’s almost always better to do things declaratively through extension points, the main reason being that doing so allows you leverage the power of rcp as a modular user interface framework . to illustrate this, let’s look at our options for laying out perspectives.

programmatic layout = centralized / hard coded

here is the simplest code needed to add a view to a perspective programmatically. to do so, we implement the iperspectivefactory interface and add a view using its string id.

public class myperspectivefactory implements iperspectivefactory {

	public void createinitiallayout(ipagelayout layout) {
		layout.addview(myview.id, ipagelayout.bottom, 0.5f, layout.geteditorarea());
	}

}

the problem here is that we’ve coupled our perspective to the view being added. this view may exist in the same plug-in as the perspective, but often it does not. if the view is in a different plug-in, we have to declare a dependency on that plug-in just to add the view. it’s possible to reduce the coupling somewhat by replacing myview.id with the actual string id itself, but hidden dependencies based on string equivalency are arguably even more smelly.

in the end, a programmatic perspective layout results in a hard-coded and centralized architecture looking like this.

perspective-layouts-central

declarative layout = decentralized / modular

the declarative approach based on extension points resolves these issues. to layout a perspective declaratively we extend the org.eclipse.ui.perspectiveextensions extension point.

<extension point="org.eclipse.ui.perspectiveextensions">
<perspectiveextension targetid="com.mycompany.myperspective">
<view id="com.mycompany.myview" minimized="false"
ratio="0.5" relationship="left" relative="org.eclipse.ui.editorss">
</view>
</perspectiveextension>
</extension>

using this approach, each plug-in adds the views that it knows about, resulting in a decentralized architecture where the plug-ins containing the views are now in control.

perspective-layouts-decentr

note that we have not eliminated all coupling, as the perspective extensions still need to refer to the perspective by its string id, but this is not as bad as it sounds. perspectives are much more static than views - you typically define them and make few changes afterwards. views, on the other hand are often moved from one plug-in to another or have their purpose (and potentially their id) redefined. decentralizing control allows you to make these kinds of changes without breaking the perspective layout.

conclusion

adding ui elements declaratively is definitely the way to go. it gives you much more flexibility (e.g. you can add views to perspectives you didn’t create) and also allows you to leverage the modular nature of the framework.

sure, there will always be cases where a declarative approach cannot be taken, particularly when some part of an api is not yet surfaced in the related extension point. but in the absence of such a need, i urge rcp developers to always turn first to the extension point mechanisms and fall back to programmatic approaches as a last resort. as your application evolves over time, you’ll really come to enjoy the flexibility and increased reusability that a declarative approach makes possible.

from http://rcpquickstart.com/

Strings Data Types Leverage (statistics) Architecture Dependency IT Interface (computing) Framework dev

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Set Up and Run Cypress Test Cases in CI/CD TeamCity
  • Build an Automated Testing Pipeline With GitLab CI/CD and Selenium Grid
  • How To Choose the Right Streaming Database
  • Seamless Integration of Azure Functions With SQL Server: A Developer's Perspective

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: