On my current project I was having some serious problems with screen refresh and I finally found a work around. The problem was I have a 4 pane perspective setup with 4+ views. The left half of the application area is a PDF viewer. When a user (me doing testing) would open a new PDF the fragments of the filedialog would remain overlayed during opening of the new PDF as well as the other views shifting over into the PDF area. The reason is because I had to do a HideView then ShowView. If I just did a close/open document function call in my swing PDF component the pdf component (I use icesoft IcePDF) would not always work. I am pretty sure this is due to the SWT to AWT bridge I have to do. So now here is the code to fix it!
Shell shell;
shell = getSite().getShell();
PDFView view = (PDFView)getSite().getPage().findView(PDFView.ID);
getSite().getPage().hideView(view);
shell.update();
Just doing a shell update seemed to do the trick, you may want to also look at this code if the above does not work for you. Look at the comments out code and it may be useful to you.
Shell shell;
shell = getSite().getShell();
// Display display = shell.getDisplay();
// Point shellSize = shell.getSize();
// shell.redraw(0,0,shellSize.x,shellSize.y,true);
PDFView view = (PDFView)getSite().getPage().findView(PDFView.ID);
getSite().getPage().hideView(view);
shell.update();
// display.update();
Showing posts with label rcp. Show all posts
Showing posts with label rcp. Show all posts
Thursday, April 17, 2008
Thursday, March 6, 2008
Numeric Only in Eclipse RCP SWT Text Widget
If you wanted to make an Eclipse RCP SWT text field numeric only here is a simple validation you can do. More to come on this as I need better support then this for like money fields, etc.
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)
{
String string = e.text;
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;
}
}
}
});
Friday, December 28, 2007
QTJava and Eclipse RCP
I have not posted in a while but thought I would do a quick post before the year ends and follow up with more detail later. Right now I am trying to get QTJava API into my Eclipse RCP application. Thanks to a friend (thanks Rick!) I have some code to help with a problem with QTJava for Eclipse RCP on the Macintosh OSX platform. Isn't that ironic? Under OSX the whole movie canvas is shifted 16 pixels right and 16 pixels down (I believe that is the offset issue, will double check in followup post). So one needs to "trick" Eclipse to think the canvas paint area is correct. I will post some code examples in January once I have all the code in and working. Stay tuned.
Merry Christmas and Happy New Year to you all!
Merry Christmas and Happy New Year to you all!
Friday, October 26, 2007
Communication between Views using eventLoopIdle
I have been working on an application that is now up to 3 swing components embedded in my Eclipse RCP / SWT application. This has become problematic having these 3rd party components to communicate properly with each other. While it is easy to communicate with these other components embedded in other views I was having a problem with RCP not properly repainting the screen. So I have come up with a work around that works for me and I thought I would share it with any other Eclipse Rich Client Platform developer out there that may be struggling.
If you open up ApplicationWorkbenchAdvisor.java - there is a function in there called public void eventLoopIdle(Display display). In this function I put my calls. I used my Application Singleton class to facilitate communication. By adding a semaphore type variable I can see if other views need to go and update their screen. In my specific case a user has a view of a PDF and when they click on an action object this needs to send the file information to a chart window that then opens the file clicked on in the PDF view, parse it and display the chart with the give options defined by the PDF link.
If you have any questions on this just email or leave me a comment. Good luck!
If you open up ApplicationWorkbenchAdvisor.java - there is a function in there called public void eventLoopIdle(Display display). In this function I put my calls. I used my Application Singleton class to facilitate communication. By adding a semaphore type variable I can see if other views need to go and update their screen. In my specific case a user has a view of a PDF and when they click on an action object this needs to send the file information to a chart window that then opens the file clicked on in the PDF view, parse it and display the chart with the give options defined by the PDF link.
If you have any questions on this just email or leave me a comment. Good luck!
Wednesday, August 22, 2007
Problems Exporting your Eclipse RCP?
Today one of the students (PhD level) came to me with a problem I had encountered before while exporting my Eclipse RCP project. Normally you click on the export wizard on your project.product page and everything works fine. But occasionally you have a problem and when you look at the log file it generates in an annoying zip file you see nothing in there or maybe some warnings. This should be working, why is it failing? Well every single time this has happened to me it was because the generated eclipse.exe file become exclusively locked. This is under Windows XP Pro. I have no idea if this is happening to people on other platforms.
You can't just delete everything in your old export folder, because the delete fails.
So how do you fix it? Well these are the only solutions that work for me:
1) If in a hurry, export to a new folder.
2) If not in a hurry, reboot your computer, remove the old folder (or all its contents), run eclipse and export your project.
Why this is such an easy answer it is surprising how many people bang their heads against the wall on this one.
You can't just delete everything in your old export folder, because the delete fails.
So how do you fix it? Well these are the only solutions that work for me:
1) If in a hurry, export to a new folder.
2) If not in a hurry, reboot your computer, remove the old folder (or all its contents), run eclipse and export your project.
Why this is such an easy answer it is surprising how many people bang their heads against the wall on this one.
Friday, August 17, 2007
Tabbed Views in Eclipse RCP
Tabbed Views in Eclipse RCP sounds really complicated but Eclipse has made this really easy. Just follow these simple instructions and you will be off and running with multiple tabbed views.
- Open your perspective.java file (If you don't have this file yet, you are in trouble!)
- in public void createInitialLayout(IPageLayout layout) you should have some code that looks similar to this:
layout.addStandaloneView(ItagTreeView.ID, true, IPageLayout.LEFT, 1.0f, editorArea);
layout.addStandaloneView(ChartView.ID, true, IPageLayout.RIGHT, 0.5f, ItagTreeView.ID);
layout.addStandaloneView(FormView.ID, true, IPageLayout.BOTTOM, 0.5f, ItagTreeView.ID);
// create a folder for multiple analysis views so that they will open up
// in tabs next to the table view.
IFolderLayout folder = layout.createFolder("Tables", IPageLayout.BOTTOM, 0.5f, ChartView.ID);
folder.addPlaceholder(AnalysisView.ID + ":*");
folder.addView(TableView.ID);
The above code has 4 views and the table view is it. Our AnalysisView is a 2nd tab under the TableView.
You can see instead of calling addStandaloneView we call createFolder. The "folder" is how we combine several views to make a tabbed view presentation.
Monday, August 6, 2007
Eclipse RCP Views - How to communicate between them
When I was starting out my Eclispe program life, which was not very long ago, I had quite the dilemna of how in the hell would I have ViewOne communicate with ViewTwo, three and four. After talking to a good friend of mine he introduced me to an old idea that still works great. Use a class called ApplicationSingleton. This class is really very handy and I thought I'd talk about it here with a simple example.
Now to talk about some parts of this class.
Easy, right? :) If you have any questions or comments I'd love to hear them!
public class ApplicationSingleton {
static private ApplicationSingleton instance;
private ItagTreeView.TreeParent chart;
public static ApplicationSingleton getInstance() {
if (instance == null) {
instance = new ApplicationSingleton();
}
return instance;
}
private ApplicationSingleton() {
super();
}
public void SetCurrentChart(ItagTreeView.TreeParent tp) {
chart = tp;
}
public ItagTreeView.TreeParent getCurrentChart() {
return chart;
}
}
Now to talk about some parts of this class.
- We include a private variable of our class called "instance"
- From our application code we make calls to getInstance(), such as this:
TreeParent tp = ApplicationSingleton.getInstance().GetCurrentChart(); The first time we call getInstance it will make an instance of this class. - By using setCurrentChart() we can store our variables in view1 and in view2 we can use getCurrentChart.
Easy, right? :) If you have any questions or comments I'd love to hear them!
Wednesday, August 1, 2007
Slush Bucket for Eclipse RCP
I have been developing an Eclipse RCP application for one of my clients. I sure wish I had started to blog it from the very beginning as I have learned so much that isn't documented properly online or in the books I have. I guess it's better late then never so here we go.
The latest stumbling block I ran into was that Eclipse SWT (their replacement to Java Swing) did not have slush buckets or also referred to as a pick list. So I decided to code my own. Now that I have I thought I would post my working code for others to use.
Below is the code as I have it and I will also throw in some very important notes about the code below the code. Such as my use of an Application Singleton class. My way of coding it may not be the most efficient, I really don't know, but it works for me and while searching for this type of code I noticed a lot of other people needed help on this too. So I helps some other Eclipse people out there!
So in my code I am doing a slush bucket to determine which columns of data should be used for logistic regression. With that said, the biggest challenge was how do I expose variables, such as the list boxes, to the selection listener events? Well you write a class called "ApplicationSingleton" that sets and gets variables that then can be used anywhere in your application by doing a getInstance of the one ApplicationSingleton class we have.
So I hope this helps and if you have any questions please let me know!
The latest stumbling block I ran into was that Eclipse SWT (their replacement to Java Swing) did not have slush buckets or also referred to as a pick list. So I decided to code my own. Now that I have I thought I would post my working code for others to use.
Below is the code as I have it and I will also throw in some very important notes about the code below the code. Such as my use of an Application Singleton class. My way of coding it may not be the most efficient, I really don't know, but it works for me and while searching for this type of code I noticed a lot of other people needed help on this too. So I helps some other Eclipse people out there!
Label loglabel = toolkit.createLabel(sectionClient, "Logistic Regression Independent Variables:");
Composite logGroup;
logGroup = new Composite(sectionClient, SWT.FLAT);
logGroup.setLayout(new GridLayout(3, false));
logGroup.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL | GridData.GRAB_HORIZONTAL));
List list = new List (logGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
GridData g = new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1);
g.heightHint = 150;
g.minimumWidth = 30;
list.setLayoutData(g);
list.setToolTipText("The source list of fields you can choose. \nHighlight the fields you wish to have as independent variables \nin the logistic regression and move to the right list box\nusing the center buttons.");
list.setItems(data[0]); // 0 is the headers
ApplicationSingleton.getInstance().setSelList(list);
Group middleGroup;
middleGroup = new Group(logGroup, SWT.FLAT);
middleGroup.setLayout(new GridLayout(1, false));
Button bright;
bright = new Button(middleGroup, SWT.PUSH);
bright.setText(">");
bright.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1));
bright.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
List list = ApplicationSingleton.getInstance().getSelList();
int [] selections;
selections = list.getSelectionIndices();
List list2 = ApplicationSingleton.getInstance().getTargetList();
for(int i=0; i < selections.length; i++)
{
list2.add(list.getItem(selections[i]));
}
list.remove(selections);
}
public void widgetDefaultSelected(SelectionEvent event) {
}
});
Button bleft;
bleft = new Button(middleGroup, SWT.PUSH);
bleft.setText("<");
bleft.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1));
bleft.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
List list2 = ApplicationSingleton.getInstance().getTargetList();
List list = ApplicationSingleton.getInstance().getSelList();
int [] selections;
selections = list2.getSelectionIndices();
for(int i=0; i < selections.length; i++)
{
list.add(list2.getItem(selections[i]));
}
list2.remove(selections);
}
public void widgetDefaultSelected(SelectionEvent event) {
}
});
Button bfullright;
bfullright = new Button(middleGroup, SWT.PUSH);
bfullright.setText(">>");
bfullright.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1));
bfullright.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
List list2 = ApplicationSingleton.getInstance().getTargetList();
List list = ApplicationSingleton.getInstance().getSelList();
String [] strings, strings2;
strings = list.getItems();
strings2 = list2.getItems();
// Combine both sets and move it all to the right
String[] temp = new String[strings.length + strings2.length];
System.arraycopy(strings, 0, temp, 0, strings.length);
System.arraycopy(strings2, 0, temp, strings.length, strings2.length);
list2.setItems(temp);
list.removeAll();
}
public void widgetDefaultSelected(SelectionEvent event) {
}
});
Button bfullleft;
bfullleft = new Button(middleGroup, SWT.PUSH);
bfullleft.setText("<<");
bfullleft.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1));
bfullleft.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
List list2 = ApplicationSingleton.getInstance().getTargetList();
List list = ApplicationSingleton.getInstance().getSelList();
String [] strings, strings2;
strings = list.getItems();
strings2 = list2.getItems();
// Combine both sets and move it all to the right
String[] temp = new String[strings.length + strings2.length];
System.arraycopy(strings, 0, temp, 0, strings.length);
System.arraycopy(strings2, 0, temp, strings.length, strings2.length);
list.setItems(temp);
list2.removeAll();
}
public void widgetDefaultSelected(SelectionEvent event) {
}
});
List list2 = new List (logGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
g = new GridData(SWT.CENTER, SWT.CENTER, true, true, 1, 1);
g.heightHint = 150;
g.minimumWidth = 30;
list2.setLayoutData(g);
ApplicationSingleton.getInstance().setTargetList(list2);
Button bRedrawChart;
bRedrawChart = new Button(logGroup, SWT.PUSH);
bRedrawChart.setText("Redraw Chart");
bRedrawChart.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 3, 2));
bRedrawChart.setToolTipText("After selecting the Indepenent Variables\nfor your Logistic Regression Click Redraw.");
bRedrawChart.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
Button b = ApplicationSingleton.getInstance().getY1LogButton();
b.setSelection(true);
ApplicationSingleton.getInstance().getCurrentChart().doY1Logistic(true);
List list2 = ApplicationSingleton.getInstance().getTargetList();
String [] strings;
strings = list2.getItems();
ApplicationSingleton.getInstance().getCurrentChart().setLogX(strings);
ChartView view = (ChartView)getSite().getWorkbenchWindow().getActivePage().findView(ChartView.ID);
view.loadNewChart();
}
public void widgetDefaultSelected(SelectionEvent event) {
}
});
So in my code I am doing a slush bucket to determine which columns of data should be used for logistic regression. With that said, the biggest challenge was how do I expose variables, such as the list boxes, to the selection listener events? Well you write a class called "ApplicationSingleton" that sets and gets variables that then can be used anywhere in your application by doing a getInstance of the one ApplicationSingleton class we have.
So I hope this helps and if you have any questions please let me know!
Subscribe to:
Posts (Atom)