If you wanted to make an Eclipse RCP SWT text field numeric only here is a simple validation you can do.
Text startText = new Text(group, SWT.BORDER);
startText.setText(txt);
startText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
startText.addListener (SWT.Verify, new Listener (){
public void handleEvent (Event e){
char [] chars = new char [string.length ()];
string.getChars (0, chars.length, chars, 0);
for (int i=0; i < chars.length; i++){
if (!(’0′ <= chars [i] && chars [i] <= ‘9′) && (chars[i]!=’.')){
e.doit = false;
return;
}
}
}
});
Daffodil Knowledge BlogsNumeric Only in Eclipse RCP SWT Text WidgetNovember 4th, 2009Customizing the UI in small RCP ProjectsNovember 4th, 2009The presentation framework provided by Eclipse gives you the possibility to customize the UI and the behavior of graphical elements. A good example for UI-customization is the Lotus Nodes Client “Hannover”. But what do you do If you don’t have the budget, time or the skill set to implement such an excessive UI-customization like the guys from “Hannover”? Especially for small RCP applications with a handful views and the wish that your product should not look like a “typical Eclipse Client” it is probably better to use alternative possibilities to create an individ ual looking RCP. The following article will give an example how to customize your UI easily without using any special framework or extension-point. Product branding with Eclipse RCPSince it is possible to build RCP applications with Eclipse, the possibilities to give your application a more personal touch through the PDE have also increased. Typical elements are for example splash-screens, program-icons or welcome-screens. But in the most cases that is not enough. The customer often has a corporate identity with logos, special colors, fonts,etc. which must be also integrated within the application. Step 1: Implementing a banner with integrated ToolbarAn often required UI-element is a banner on top of your views with a company logo or the name of your product and a toolbar where the key features of the application are accessible. This is possible if your overwrite the method WorkbenchWindowAdvisor#createWindowContents(Shell shell). Eclipse layouts and creates typical elements of your workbench like the Coolbar, MenuBar and the Statusline. If you overwrite this method you have the freedom to arrange the content of your window but you also have to care for the correct initialization of all UI-elements needed. This step is very effective and your application looks much more personalized (see picture).
Step 2: Implement your own Viewpart-Title AreaThe most characteristic element to indicate a “typical Eclipse application” is the look of a viewpart with the curved title and the appended action bar.
Step 3: Move your Progress IndicatorThis is an optional step, depending on your requirements. In nearly every application you have jobs for background-processes where you need a progress indicator to give the user a feedback about the job-status. The default-location of the progress indicator is on the bottom of your application window outside the page contents. It doesn’t make sense in small applications, that this little, but important widget needs the whole bottom of your workbench-window, especially if you don’t have a status-bar. So why not place the progress-bar somewhere else, e.g. in a viewpart?- In spite of the “Discouraged Access Warning” you can implement the org.eclipse.ui.internal.progress.ProgressRegion wherever you want (see picture).
ExampleI have implemented a small RCP application, which uses the mentioned UI-customizations (see picture). Check it out (or download) to see, how easyily an individual UI can be implemented. But remember: The discussed issues can be realized only for a special type of RCPs. If you have to customize your “Next generation IDE” with 100 views and editors, please use the presentation framework. ConclusionThere are many ways to customize your Eclipse RCP Application. Based on the special requirements of your personal application you have to choose the best toolkit to reach your goal. |




