Maintaining expanded/collapsed state in Eclipse TreeViewer

JFace TreeViewer is a very useful UI control for displaying hierarchical data. It is used extensively in Eclipse, for example in Project/Package/Navigator view, Outline view, Debug Variables view etc. Eclipse .org hosts a nice article on TreeViewer – How to use the JFace Tree Viewer.

To specify data and its hierarchy in the TreeViewer, you implement ITreeContentProvider interface. This interface has methods like getElements, getChildren which you need to override to provide content and structure to the TreeViewer. You would typically return array of your model objects from getElements or getChildren methods. And since it is a tree view, you can expand or collapse the nodes. The model classes for an example in the above article could be Category (book, game etc.), Book and Game. Category can have Books or Games. You might load this information from a database and pass it to the content provider object. To refresh information in the TreeViewer, you would call one of the variants of refresh() function.

Continue reading “Maintaining expanded/collapsed state in Eclipse TreeViewer”

Remote JavaScript debugging with Chrome Developer Tools

I have been using Chrome Developer Tools (CDT) for the past couple of weeks to build a JavaScript debugger. Though you can debug JavaScript in Chrome browser itself, my requirement was such that I needed a debugger that runs outside Chrome and debugs pages running in Chrome. I found that Chrome Developer Tools provides a JavaScript debugger plugin for Eclipse. CDT has exposed Java APIs, if you want to build the debugger yourself. It also has exposed JavaScript APIs for its debugger.

So I first evaluated Eclipse plugin that CDT provides. Before I get to that plugin, here are some useful links about CDT –
Continue reading “Remote JavaScript debugging with Chrome Developer Tools”

Record and Playback Drawing in HTML5 Canvas

A few months back I had created an application that recorded and played back drawings on HTML5 Canvas. For some time now I wanted to refactor the code in that application and create a reusable ‘component’ from it. Which is what I did this week.

Go ahead and try the demo first – Press ‘Record’ key below and then draw some strokes/lines in the box with the mouse (holding down left button). Once you are done, click Stop button. Click ‘Play’ button to play back the drawing you just drew. You can pause and resume too.

Continue reading “Record and Playback Drawing in HTML5 Canvas”

"Access restriction" error in Eclipse plugins

I spent quite a lot of time today trying to debug “Access restriction” error in one of my Eclipse plugins. In the last four years of Eclipse plugin development, I don’t recall ever facing this issue, but today suddenly some of the imports in one of the classes in my Eclipse plugin were flagged off as errors –

Access restriction: The type ISelection is not accessible due to restriction on required library <eclipse-path>\eclipse\plugins\org.eclipse.jface_3.6.1.M20100825-0800.jar

I had seen warnings about ‘restricted access’ for some of the imports earlier, but those were for classes that Eclipse discouraged to use e,g, for internal Eclipse classes. But today I was seeing errors.

The error does not tell much about what could have gone wrong. ISelection is exported from jface plugin and it is a public interface. And I had used this class without any error in other plugins.

Continue reading “"Access restriction" error in Eclipse plugins”

Eclipse SWT GridLayout – Making the widget fill horizontally

I have been stuck with the problem of making UI widgets fill horizontally in a grid layout a few times. The solution is simple, but when I have to create UI using Eclipse SWT after a long gap, I tend to forget how I had made this work earlier, so I decided to blog about this.

I had to create a simple UI with one label and associated text box. I coded it like this –

GridLayout layout = new GridLayout(2, false);
tabContainer.setLayout(layout); //this is the parent composite

Label label1 = new Label(tabContainer, SWT.NONE);
label1.setText("Some Label:");
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = false;

Text txtBox1 = new Text(tabContainer, SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;

Continue reading “Eclipse SWT GridLayout – Making the widget fill horizontally”

Starting Android Activity on device restart

I finally got around to fixing a bug in my Android application, Simple Task Reminder, which was on my to-do list for a long time.The issue was that all reminders set in this application were lost on device restart. The solution was to set reminders again after device rebooted.

Android SDK provides a mechanism to receive notification for your application, after the device is booted. You need to add a broadcast receiver in the manifest file –
Continue reading “Starting Android Activity on device restart”

Developing Database Applications with WebAppRunner

WebAppRunner is the Eclipse RCP application I created to run web applications as standalone desktop applications. I had explained earlier how this application could be used by creating a demo FileList application. In this post I am going to show how WebAppRunner can be used to create Database applications.

I have created a demo application, SQLiteApp.

Continue reading “Developing Database Applications with WebAppRunner”

Hiding menu and tool bars in Eclipse RCP Application

I wanted to hide/show menu bar in my WebAppRunner Eclipse application, depending on settings. I figured getting menu bar manager and calling setVisible method would do the job, but it was not sufficient.

Eclipse checks visibility of each menu manager in the menu bar and even if one of them is visible, it would not hide the menu bar after calling setVisible(false).

Continue reading “Hiding menu and tool bars in Eclipse RCP Application”

WebAppRunner – Run your web applications standalone

Last week I wrote a blog post about how Java objects can be passed to JavaScript code running in the SWT Browser control. I mentioned that I was working on an Eclipse RCP app that could run web apps as standalone apps in the SWT browser control.

That application is now ready. If you want to give it a try, download it from following links. The application is about 21 MB in size.

JRE is not packaged in the above application. You will have to download and install it, if you don’t have it already.

I have also created a sample app to show how a web page can call Java APIs. The application uses JDK File APIs to get list of files. Download FileListApp from here. Below is a screen shot of this application –

Continue reading “WebAppRunner – Run your web applications standalone”

Using Java Objects in JavaScript in Eclipse SWT Browser Control

I have been developing Eclipse plugins for more than four years now. I have implemented many features in the ColdFusion Builder, which is an Eclipse based IDE. Eclipse SDK provides a SWT Browser control which can be used within Eclipse plugin to display HTML files. Eclipse does not include any browser, but it uses the system browser- on Windows it is Internet Explorer and on Macintosh it is Safari. I have used this control mainly to display static HTML content or open a URL on a remote server, e.g. for executing ColdFusion Builder extensions written in CFML.

Recently I have been doing a lot of mobile application dev elopement, and saw how easy it was to invoke Java objects from JavaScript in Android. I have blogged about this in one of my posts, Creating Android Applications with HTML User Interface. This got me thinking that it would be nice if SWT Browser control would also provide some way to pass Java Objects to JavaScript. Turned out that it is possible.

Continue reading “Using Java Objects in JavaScript in Eclipse SWT Browser Control”