Home » Newcomers » Newcomers » Starting RCP programming
Starting RCP programming [message #258547] |
Fri, 13 June 2008 13:47  |
Eclipse User |
|
|
|
I am trying to run the program below.
It came out of Java Developer's Guide to Eclipse.
It is a beginning program to show a simple RCP.
But (of course)
I get 2 errors:
A. (At the very beginning of the code)
The type org.eclipse.core.runtime.IConfigurationElement cannot be
resolved. It is indirectly referenced from required .class files
and
B. (on public class SWTView extends ViewPart implements SelectionListener,
ViewPart is in Red) The type
org.eclipse.core.runtime.IExecutableExtension cannot be resolved. It is
indirectly referenced from required .class files
I have:
Eclipse SDK
Version: 3.3.2
Build id: M20080221-1800
If you like I will send a "screen shot" of Eclipse and the jar file:
C:\eclipse-rcp\swt-3.4RC3-win32-win32-x86\org.eclipse.core.c ommands_3.3.0.I20070605-0010.jar
expanded. It does not show (and/or any other jar file)
IExecutableExtension or IConfigurationElement anywhere.
You should be able to grab all the code below and
put it into Eclipse to see the errors.
Thanks
Bill B.
/*
* "The Java Developer's Guide to Eclipse"
* by D'Anjou, Fairbrother, Kehn, Kellerman, McCarthy
*
* (C) Copyright International Business Machines Corporation, 2003, 2004.
* All Rights Reserved.
*
* Code or samples provided herein are provided without warranty of any
kind.
*/
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.*;
import org.eclipse.ui.part.*;
/*
import org.eclipse.core.internal.runtime.*;
import org.eclipse.core.commands.*;
import org.eclipse.core.commands.common.*;
import org.eclipse.core.commands.contexts.*;
import org.eclipse.core.commands.operations.*;
import org.eclipse.core.commands.util.*;
import org.eclipse.core.internal.*;
import org.eclipse.core.internal.commands.*;
import org.eclipse.core.internal.commands.operations.*;
import org.eclipse.core.internal.commands.util.*;
import org.eclipse.core.internal.preferences.*;
import org.eclipse.core.internal.preferences.legacy.*;
import org.eclipse.core.internal.runtime.*;
import org.eclipse.core.runtime.*;
*/
/**
* Displays a variety of SWT controls using an Eclipse
* view as the container.
*/
public class SWTView extends ViewPart implements SelectionListener {
private StyledText myText;
private Shell workbenchShell;
private Font font;
static String[] ListData1 =
{
"Dan",
"Jim",
"John",
"Pat",
"Scott",
"The Gang of Five" };
public void setFocus() {
}
/**
* Create the contents of the view.
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composit e)
*/
public void createPartControl(Composite parent) {
workbenchShell =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l();
open(parent);
}
/**
* Populate the widgets into the view container.
*/
protected void open(Composite parent) {
parent.setLayout(new org.eclipse.swt.layout.GridLayout());
parent.setLayoutData(new GridData(GridData.GRAB_VERTICAL));
createButtons(parent);
createStyledText(parent);
createList(parent);
createProgressBar(parent);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
/**
* Listener for Button b1.
* @see SWTView#createButtons(Composite)
* @see
org.eclipse.swt.events.SelectionListener#widgetSelected(Sele ctionEvent)
*/
public void widgetSelected(SelectionEvent e) {
MessageDialog.openInformation(
null,
"ButtonTextExample",
"Hello from JDG2E! ");
myText.setText("Hello, from the authors of The Java Developer's Guide to
Eclipse");
}
/**
* Creates the buttons that display the Message and File dialogs
* and their selection listeners.
*/
public void createButtons(Composite parent) {
Group group = new Group(parent, SWT.NONE);
group.setLayout(new GridLayout());
group.setText("Buttons");
group.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
Button b1 = new Button(group, SWT.PUSH);
b1.setText("Show Messagebox");
b1.setFocus();
b1.addSelectionListener(this);
Button b2 = new Button(group, SWT.PUSH);
b2.setText("Show File Dialog");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(workbenchShell, SWT.OPEN);
dialog.setFilterExtensions(new String[] { "*.jar;*.zip" });
String selectedFile = dialog.open();
if (selectedFile == null)
selectedFile = "None";
MessageDialog.openInformation(
null,
"Selected File",
selectedFile);
}
});
}
/**
* Creates the List widget and selection listener.
*/
public void createList(Composite parent) {
Group groupList = new Group(parent, SWT.NULL);
groupList.setLayout(new GridLayout());
groupList.setText("List");
groupList.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
List myList =
new List(
groupList,
SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
GridData gd = new GridData();
// Define a 100 pixel square cell so widget displays scrollbars
gd.heightHint = 100;
gd.widthHint = 100;
myList.setLayoutData(gd);
myList.setItems(ListData1);
myList.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
System.out.println("List item selected");
}
public void widgetDefaultSelected(SelectionEvent e) {
System.out.println("List item default selected");
}
});
}
/**
* Creates a rich text widget, sets its font,
* and defines event listeners.
*/
public void createStyledText(Composite parent) {
Group group2 = new Group(parent, SWT.NULL);
group2.setLayout(new GridLayout());
group2.setText("Styled Text");
group2.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
myText = new StyledText(group2, SWT.SINGLE | SWT.BORDER);
myText.setText("abcdef");
font =
new Font(
myText.getDisplay(),
new FontData("Courier", 14, SWT.BOLD));
myText.setFont(font);
myText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
myText.setSize(90, 25);
myText.redraw();
System.out.println("Got new text");
}
});
myText.addControlListener(new ControlListener() {
public void controlResized(ControlEvent e) {
System.out.println("Control Resized");
}
public void controlMoved(ControlEvent e) {
}
});
}
/**
* Basic demonstration of UI and non-UI thread synchronization.
* Creates a progress bar and button to run it in another thread.
* Progress bar is updated in the non-UI thread using Display.asyncExec
method.
* Half way through processing the user is notified using
Display.syncExec method.
* @see org.eclipse.swt.widgets.Display#syncExec(Runnable)
* @see org.eclipse.swt.widgets.Display#asyncExec(Runnable)
*/
public void createProgressBar(Composite parent) {
final Display display = Display.getCurrent();
Group groupPB = new Group(parent, SWT.NULL);
groupPB.setLayout(new GridLayout());
groupPB.setText("Thread Synchronization");
groupPB.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
final ProgressBar bar = new ProgressBar(groupPB, SWT.SMOOTH);
bar.setBounds(10, 10, 200, 32);
final int maximum = bar.getMaximum();
final Button buttonPB = new Button(groupPB, SWT.PUSH);
final MessageDialog[] halfwayDialog = new MessageDialog[1];
buttonPB.setText("Fill Progress Bar");
buttonPB.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
halfwayDialog[0] =
new MessageDialog(
null,
"Synchronized Dialog",
null,
"Halfway done!",
MessageDialog.INFORMATION,
new String[] { IDialogConstants.OK_LABEL },
0);
halfwayDialog[0].setBlockOnOpen(false);
buttonPB.setEnabled(false);
new Thread() {
public void run() {
System.out.println("Thread started");
for (final int[] i = new int[1];
i[0] <= maximum;
i[0]++) {
try {
Thread.sleep(50);
} catch (Throwable th) {
}
System.out.println("Thread processing " + i[0]);
display.asyncExec(new Runnable() {
public void run() {
System.out.println(
"Async UI interrupt " + i[0]);
if (bar.isDisposed())
return;
bar.setSelection(i[0]);
}
});
// inform user that halfway point reached
if (i[0] == maximum / 2) {
System.out.println(
">>>>>>>>>>>>>>>>>>Halfway point");
display.syncExec(new Runnable() {
public void run() {
// executing this dialog outside Display.syncExec
// causes invalid thread access error.
halfwayDialog[0].open();
}
});
}
if (i[0] > (maximum * 3) / 4) {
display.syncExec(new Runnable() {
public void run() {
halfwayDialog[0].close();
}
});
}
}
System.out.println("Thread finished");
display.syncExec(new Runnable() {
public void run() {
if (!buttonPB.isDisposed())
buttonPB.setEnabled(true);
halfwayDialog[0].close();
}
});
}
}
.start();
}
});
}
/**
* Disposes of the font.
* @see SWTView#createStyledText(Composite)
* @see org.eclipse.ui.IWorkbenchPart#dispose()
*/
public void dispose() {
super.dispose();
font.dispose();
System.out.println("Font disposed");
}
}
|
|
| | | |
Re: Starting RCP programming [message #258677 is a reply to message #258566] |
Mon, 16 June 2008 10:13   |
Eclipse User |
|
|
|
To all Eclipse people:
To get the program/code, below, to work,
I had to put these jar files into my "Referenced Libraries" of my project:
swt.jar
org.eclipse.jface_3.3.2.M20080207-0800.jar
org.eclipse.ui_3.3.1.M20071128-0800.jar
org.eclipse.ui.workbench_3.3.2.M20080207-0800.jar
org.eclipse.core.commands_3.3.0.I20070605-0010.jar
org.eclipse.equinox.common_3.3.0.v20070426.jar
org.eclipse.equinox.registry_3.3.1.R33x_v20070802.jar
These jar files (except swt.jar) are in my C:\eclipse-rcp\eclipse\plugins.
I have been assuming that C:\eclipse-rcp\eclipse\plugins is my "default"
plugin/jar directory. So I never had to put them into the "Referenced
Libraries".
This truth is NOT self-evident (NOT plain and clear to sight,
understanding or Eclipse) nor true.
I have spent 2 days, (wasted) getting this corrected.
My personal opinion is the Quality Assurance of Eclipse is very poor.
Thus Eclipse as a dependable tool is not true.
/*
* "The Java Developer's Guide to Eclipse"
* by D'Anjou, Fairbrother, Kehn, Kellerman, McCarthy
*
* (C) Copyright International Business Machines Corporation, 2003, 2004.
* All Rights Reserved.
*
* Code or samples provided herein are provided without warranty of any
kind.
*/
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.*;
/**
* Displays a variety of SWT controls using an Eclipse
* view as the container.
*/
public class SWTView extends ViewPart implements SelectionListener {
private StyledText myText;
private Shell workbenchShell;
private Font font;
static String[] ListData1 =
{
"Dan",
"Jim",
"John",
"Pat",
"Scott",
"The Gang of Five" };
public void setFocus() {
}
/**
* Create the contents of the view.
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composit e)
*/
public void createPartControl(Composite parent) {
workbenchShell =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l();
open(parent);
}
/**
* Populate the widgets into the view container.
*/
protected void open(Composite parent) {
parent.setLayout(new org.eclipse.swt.layout.GridLayout());
parent.setLayoutData(new GridData(GridData.GRAB_VERTICAL));
createButtons(parent);
createStyledText(parent);
createList(parent);
createProgressBar(parent);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
/**
* Listener for Button b1.
* @see SWTView#createButtons(Composite)
* @see
org.eclipse.swt.events.SelectionListener#widgetSelected(Sele ctionEvent)
*/
public void widgetSelected(SelectionEvent e) {
MessageDialog.openInformation(
null,
"ButtonTextExample",
"Hello from JDG2E! ");
myText.setText("Hello, from the authors of The Java Developer's Guide to
Eclipse");
}
/**
* Creates the buttons that display the Message and File dialogs
* and their selection listeners.
*/
public void createButtons(Composite parent) {
Group group = new Group(parent, SWT.NONE);
group.setLayout(new GridLayout());
group.setText("Buttons");
group.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
Button b1 = new Button(group, SWT.PUSH);
b1.setText("Show Messagebox");
b1.setFocus();
b1.addSelectionListener(this);
Button b2 = new Button(group, SWT.PUSH);
b2.setText("Show File Dialog");
b2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(workbenchShell, SWT.OPEN);
dialog.setFilterExtensions(new String[] { "*.jar;*.zip" });
String selectedFile = dialog.open();
if (selectedFile == null)
selectedFile = "None";
MessageDialog.openInformation(
null,
"Selected File",
selectedFile);
}
});
}
/**
* Creates the List widget and selection listener.
*/
public void createList(Composite parent) {
Group groupList = new Group(parent, SWT.NULL);
groupList.setLayout(new GridLayout());
groupList.setText("List");
groupList.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
List myList =
new List(
groupList,
SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
GridData gd = new GridData();
// Define a 100 pixel square cell so widget displays scrollbars
gd.heightHint = 100;
gd.widthHint = 100;
myList.setLayoutData(gd);
myList.setItems(ListData1);
myList.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
System.out.println("List item selected");
}
public void widgetDefaultSelected(SelectionEvent e) {
System.out.println("List item default selected");
}
});
}
/**
* Creates a rich text widget, sets its font,
* and defines event listeners.
*/
public void createStyledText(Composite parent) {
Group group2 = new Group(parent, SWT.NULL);
group2.setLayout(new GridLayout());
group2.setText("Styled Text");
group2.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
myText = new StyledText(group2, SWT.SINGLE | SWT.BORDER);
myText.setText("abcdef");
font =
new Font(
myText.getDisplay(),
new FontData("Courier", 14, SWT.BOLD));
myText.setFont(font);
myText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
myText.setSize(90, 25);
myText.redraw();
System.out.println("Got new text");
}
});
myText.addControlListener(new ControlListener() {
public void controlResized(ControlEvent e) {
System.out.println("Control Resized");
}
public void controlMoved(ControlEvent e) {
}
});
}
/**
* Basic demonstration of UI and non-UI thread synchronization.
* Creates a progress bar and button to run it in another thread.
* Progress bar is updated in the non-UI thread using Display.asyncExec
method.
* Half way through processing the user is notified using
Display.syncExec method.
* @see org.eclipse.swt.widgets.Display#syncExec(Runnable)
* @see org.eclipse.swt.widgets.Display#asyncExec(Runnable)
*/
public void createProgressBar(Composite parent) {
final Display display = Display.getCurrent();
Group groupPB = new Group(parent, SWT.NULL);
groupPB.setLayout(new GridLayout());
groupPB.setText("Thread Synchronization");
groupPB.setLayoutData(
new GridData(
GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
final ProgressBar bar = new ProgressBar(groupPB, SWT.SMOOTH);
bar.setBounds(10, 10, 200, 32);
final int maximum = bar.getMaximum();
final Button buttonPB = new Button(groupPB, SWT.PUSH);
final MessageDialog[] halfwayDialog = new MessageDialog[1];
buttonPB.setText("Fill Progress Bar");
buttonPB.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
halfwayDialog[0] =
new MessageDialog(
null,
"Synchronized Dialog",
null,
"Halfway done!",
MessageDialog.INFORMATION,
new String[] { IDialogConstants.OK_LABEL },
0);
halfwayDialog[0].setBlockOnOpen(false);
buttonPB.setEnabled(false);
new Thread() {
public void run() {
System.out.println("Thread started");
for (final int[] i = new int[1];
i[0] <= maximum;
i[0]++) {
try {
Thread.sleep(50);
} catch (Throwable th) {
}
System.out.println("Thread processing " + i[0]);
display.asyncExec(new Runnable() {
public void run() {
System.out.println(
"Async UI interrupt " + i[0]);
if (bar.isDisposed())
return;
bar.setSelection(i[0]);
}
});
// inform user that halfway point reached
if (i[0] == maximum / 2) {
System.out.println(
">>>>>>>>>>>>>>>>>>Halfway point");
display.syncExec(new Runnable() {
public void run() {
// executing this dialog outside Display.syncExec
// causes invalid thread access error.
halfwayDialog[0].open();
}
});
}
if (i[0] > (maximum * 3) / 4) {
display.syncExec(new Runnable() {
public void run() {
halfwayDialog[0].close();
}
});
}
}
System.out.println("Thread finished");
display.syncExec(new Runnable() {
public void run() {
if (!buttonPB.isDisposed())
buttonPB.setEnabled(true);
halfwayDialog[0].close();
}
});
}
}
.start();
}
});
}
/**
* Disposes of the font.
* @see SWTView#createStyledText(Composite)
* @see org.eclipse.ui.IWorkbenchPart#dispose()
*/
public void dispose() {
super.dispose();
font.dispose();
System.out.println("Font disposed");
}
}
|
|
|
Re: Starting RCP programming [message #258685 is a reply to message #258677] |
Mon, 16 June 2008 10:49   |
Eclipse User |
|
|
|
The Java Developer's Guide to Eclipse, 2nd edition was published in
2004. Frankly, that was a long time ago and a lot has changed in
Eclipse.
I understand your frustration. Getting started with Eclipse can be
challenging. There is a lot to learn. Managing dependencies is pretty
weird at first. But once you get over that hump, things do get a lot
easier.
FWIW, on Eclipse 3.4, I have this code running with only org.eclipse.ui
and org.eclipse.core.runtime in my plug-in manifest's "Required
Plug-ins" section.
Can you attach your plug-in project so we can have a look and see if we
can steer you in the right direction?
Wayne
On Mon, 2008-06-16 at 14:13 +0000, Bill Bollinger wrote:
> To all Eclipse people:
>
> To get the program/code, below, to work,
> I had to put these jar files into my "Referenced Libraries" of my project:
> swt.jar
> org.eclipse.jface_3.3.2.M20080207-0800.jar
> org.eclipse.ui_3.3.1.M20071128-0800.jar
> org.eclipse.ui.workbench_3.3.2.M20080207-0800.jar
> org.eclipse.core.commands_3.3.0.I20070605-0010.jar
> org.eclipse.equinox.common_3.3.0.v20070426.jar
> org.eclipse.equinox.registry_3.3.1.R33x_v20070802.jar
>
> These jar files (except swt.jar) are in my C:\eclipse-rcp\eclipse\plugins.
> I have been assuming that C:\eclipse-rcp\eclipse\plugins is my "default"
> plugin/jar directory. So I never had to put them into the "Referenced
> Libraries".
>
> This truth is NOT self-evident (NOT plain and clear to sight,
> understanding or Eclipse) nor true.
>
> I have spent 2 days, (wasted) getting this corrected.
>
> My personal opinion is the Quality Assurance of Eclipse is very poor.
> Thus Eclipse as a dependable tool is not true.
>
>
>
>
>
> /*
> * "The Java Developer's Guide to Eclipse"
> * by D'Anjou, Fairbrother, Kehn, Kellerman, McCarthy
> *
> * (C) Copyright International Business Machines Corporation, 2003, 2004.
> * All Rights Reserved.
> *
> * Code or samples provided herein are provided without warranty of any
> kind.
> */
>
> import org.eclipse.jface.dialogs.IDialogConstants;
> import org.eclipse.jface.dialogs.MessageDialog;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.StyledText;
> import org.eclipse.swt.events.ControlEvent;
> import org.eclipse.swt.events.ControlListener;
> import org.eclipse.swt.events.ModifyEvent;
> import org.eclipse.swt.events.ModifyListener;
> import org.eclipse.swt.events.SelectionAdapter;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.events.SelectionListener;
> import org.eclipse.swt.graphics.Font;
> import org.eclipse.swt.graphics.FontData;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.FileDialog;
> import org.eclipse.swt.widgets.Group;
> import org.eclipse.swt.widgets.List;
> import org.eclipse.swt.widgets.ProgressBar;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.ui.PlatformUI;
> import org.eclipse.ui.part.*;
>
> /**
> * Displays a variety of SWT controls using an Eclipse
> * view as the container.
> */
> public class SWTView extends ViewPart implements SelectionListener {
>
> private StyledText myText;
> private Shell workbenchShell;
> private Font font;
> static String[] ListData1 =
> {
> "Dan",
> "Jim",
> "John",
> "Pat",
> "Scott",
> "The Gang of Five" };
>
> public void setFocus() {
> }
>
> /**
> * Create the contents of the view.
> * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(Composit e)
> */
> public void createPartControl(Composite parent) {
> workbenchShell =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShel l();
> open(parent);
> }
>
> /**
> * Populate the widgets into the view container.
> */
> protected void open(Composite parent) {
> parent.setLayout(new org.eclipse.swt.layout.GridLayout());
> parent.setLayoutData(new GridData(GridData.GRAB_VERTICAL));
>
> createButtons(parent);
> createStyledText(parent);
> createList(parent);
> createProgressBar(parent);
> }
>
> public void widgetDefaultSelected(SelectionEvent e) {
> }
>
> /**
> * Listener for Button b1.
> * @see SWTView#createButtons(Composite)
> * @see
> org.eclipse.swt.events.SelectionListener#widgetSelected(Sele ctionEvent)
> */
> public void widgetSelected(SelectionEvent e) {
>
> MessageDialog.openInformation(
> null,
> "ButtonTextExample",
> "Hello from JDG2E! ");
> myText.setText("Hello, from the authors of The Java Developer's Guide to
> Eclipse");
> }
>
> /**
> * Creates the buttons that display the Message and File dialogs
> * and their selection listeners.
> */
> public void createButtons(Composite parent) {
> Group group = new Group(parent, SWT.NONE);
> group.setLayout(new GridLayout());
> group.setText("Buttons");
> group.setLayoutData(
> new GridData(
> GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
> Button b1 = new Button(group, SWT.PUSH);
> b1.setText("Show Messagebox");
> b1.setFocus();
> b1.addSelectionListener(this);
>
> Button b2 = new Button(group, SWT.PUSH);
> b2.setText("Show File Dialog");
> b2.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> FileDialog dialog = new FileDialog(workbenchShell, SWT.OPEN);
> dialog.setFilterExtensions(new String[] { "*.jar;*.zip" });
> String selectedFile = dialog.open();
> if (selectedFile == null)
> selectedFile = "None";
> MessageDialog.openInformation(
> null,
> "Selected File",
> selectedFile);
> }
> });
> }
>
> /**
> * Creates the List widget and selection listener.
> */
> public void createList(Composite parent) {
> Group groupList = new Group(parent, SWT.NULL);
> groupList.setLayout(new GridLayout());
> groupList.setText("List");
> groupList.setLayoutData(
> new GridData(
> GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
> List myList =
> new List(
> groupList,
> SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER);
> GridData gd = new GridData();
> // Define a 100 pixel square cell so widget displays scrollbars
> gd.heightHint = 100;
> gd.widthHint = 100;
> myList.setLayoutData(gd);
> myList.setItems(ListData1);
> myList.addSelectionListener(new SelectionListener() {
> public void widgetSelected(SelectionEvent e) {
> System.out.println("List item selected");
> }
> public void widgetDefaultSelected(SelectionEvent e) {
> System.out.println("List item default selected");
> }
> });
> }
>
> /**
> * Creates a rich text widget, sets its font,
> * and defines event listeners.
> */
> public void createStyledText(Composite parent) {
> Group group2 = new Group(parent, SWT.NULL);
> group2.setLayout(new GridLayout());
> group2.setText("Styled Text");
> group2.setLayoutData(
> new GridData(
> GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
> myText = new StyledText(group2, SWT.SINGLE | SWT.BORDER);
> myText.setText("abcdef");
> font =
> new Font(
> myText.getDisplay(),
> new FontData("Courier", 14, SWT.BOLD));
> myText.setFont(font);
> myText.addModifyListener(new ModifyListener() {
> public void modifyText(ModifyEvent e) {
> myText.setSize(90, 25);
> myText.redraw();
> System.out.println("Got new text");
> }
> });
> myText.addControlListener(new ControlListener() {
> public void controlResized(ControlEvent e) {
>
> System.out.println("Control Resized");
> }
> public void controlMoved(ControlEvent e) {
> }
> });
> }
>
> /**
> * Basic demonstration of UI and non-UI thread synchronization.
> * Creates a progress bar and button to run it in another thread.
> * Progress bar is updated in the non-UI thread using Display.asyncExec
> method.
> * Half way through processing the user is notified using
> Display.syncExec method.
> * @see org.eclipse.swt.widgets.Display#syncExec(Runnable)
> * @see org.eclipse.swt.widgets.Display#asyncExec(Runnable)
> */
> public void createProgressBar(Composite parent) {
> final Display display = Display.getCurrent();
> Group groupPB = new Group(parent, SWT.NULL);
> groupPB.setLayout(new GridLayout());
> groupPB.setText("Thread Synchronization");
> groupPB.setLayoutData(
> new GridData(
> GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
> final ProgressBar bar = new ProgressBar(groupPB, SWT.SMOOTH);
> bar.setBounds(10, 10, 200, 32);
> final int maximum = bar.getMaximum();
> final Button buttonPB = new Button(groupPB, SWT.PUSH);
> final MessageDialog[] halfwayDialog = new MessageDialog[1];
> buttonPB.setText("Fill Progress Bar");
> buttonPB.addSelectionListener(new SelectionAdapter() {
> public void widgetSelected(SelectionEvent e) {
> halfwayDialog[0] =
> new MessageDialog(
> null,
> "Synchronized Dialog",
> null,
> "Halfway done!",
> MessageDialog.INFORMATION,
> new String[] { IDialogConstants.OK_LABEL },
> 0);
> halfwayDialog[0].setBlockOnOpen(false);
> buttonPB.setEnabled(false);
> new Thread() {
> public void run() {
> System.out.println("Thread started");
> for (final int[] i = new int[1];
> i[0] <= maximum;
> i[0]++) {
> try {
> Thread.sleep(50);
> } catch (Throwable th) {
> }
> System.out.println("Thread processing " + i[0]);
> display.asyncExec(new Runnable() {
> public void run() {
> System.out.println(
> "Async UI interrupt " + i[0]);
> if (bar.isDisposed())
> return;
> bar.setSelection(i[0]);
> }
> });
> // inform user that halfway point reached
> if (i[0] == maximum / 2) {
> System.out.println(
> ">>>>>>>>>>>>>>>>>>Halfway point");
> display.syncExec(new Runnable() {
> public void run() {
> // executing this dialog outside Display.syncExec
> // causes invalid thread access error.
> halfwayDialog[0].open();
> }
> });
> }
> if (i[0] > (maximum * 3) / 4) {
> display.syncExec(new Runnable() {
> public void run() {
> halfwayDialog[0].close();
> }
> });
> }
> }
> System.out.println("Thread finished");
> display.syncExec(new Runnable() {
> public void run() {
> if (!buttonPB.isDisposed())
> buttonPB.setEnabled(true);
> halfwayDialog[0].close();
> }
> });
> }
> }
> .start();
> }
> });
> }
>
> /**
> * Disposes of the font.
> * @see SWTView#createStyledText(Composite)
> * @see org.eclipse.ui.IWorkbenchPart#dispose()
> */
> public void dispose() {
> super.dispose();
> font.dispose();
> System.out.println("Font disposed");
> }
> }
>
|
|
|
Re: Starting RCP programming [message #258706 is a reply to message #258685] |
Mon, 16 June 2008 15:14   |
Eclipse User |
|
|
|
Sorry for "shooting off my mouth" but
when your going by a book that seems complete (1000+ pages),
you would think the examples given have something
written about them, there is nothing.
I finally went back to the CD that contains the sample code,
and they needed 15 "Plug-In References"
I just needed 6 plug-in's. And you 2 plug-in's.
I am using:
http://www.eclipse.org/newsportal/post.php?type=reply&id =24387&group=eclipse.newcomer
and there is no "Attachment" button or something.
How would I send the Zip file to you?
Wayne Beaton wrote:
> The Java Developer's Guide to Eclipse, 2nd edition was published in
> 2004. Frankly, that was a long time ago and a lot has changed in
> Eclipse.
> I understand your frustration. Getting started with Eclipse can be
> challenging. There is a lot to learn. Managing dependencies is pretty
> weird at first. But once you get over that hump, things do get a lot
> easier.
> FWIW, on Eclipse 3.4, I have this code running with only org.eclipse.ui
> and org.eclipse.core.runtime in my plug-in manifest's "Required
> Plug-ins" section.
> Can you attach your plug-in project so we can have a look and see if we
> can steer you in the right direction?
> Wayne
> On Mon, 2008-06-16 at 14:13 +0000, Bill Bollinger wrote:
|
|
|
Re: Starting RCP programming [message #258709 is a reply to message #258706] |
Mon, 16 June 2008 15:25  |
Eclipse User |
|
|
|
My newsreader (Evolution) lets me attach files to newsgroup messages.
I'm guessing that yours doesn't.
If you email it to me (wayne@eclipse.org), I can post it here for you.
Wayne
On Mon, 2008-06-16 at 19:14 +0000, Bill Bollinger wrote:
> Sorry for "shooting off my mouth" but
> when your going by a book that seems complete (1000+ pages),
> you would think the examples given have something
> written about them, there is nothing.
>
> I finally went back to the CD that contains the sample code,
> and they needed 15 "Plug-In References"
> I just needed 6 plug-in's. And you 2 plug-in's.
>
> I am using:
> http://www.eclipse.org/newsportal/post.php?type=reply&id =24387&group=eclipse.newcomer
>
> and there is no "Attachment" button or something.
> How would I send the Zip file to you?
> Wayne Beaton wrote:
>
> > The Java Developer's Guide to Eclipse, 2nd edition was published in
> > 2004. Frankly, that was a long time ago and a lot has changed in
> > Eclipse.
>
> > I understand your frustration. Getting started with Eclipse can be
> > challenging. There is a lot to learn. Managing dependencies is pretty
> > weird at first. But once you get over that hump, things do get a lot
> > easier.
>
> > FWIW, on Eclipse 3.4, I have this code running with only org.eclipse.ui
> > and org.eclipse.core.runtime in my plug-in manifest's "Required
> > Plug-ins" section.
>
> > Can you attach your plug-in project so we can have a look and see if we
> > can steer you in the right direction?
>
> > Wayne
>
> > On Mon, 2008-06-16 at 14:13 +0000, Bill Bollinger wrote:
>
>
|
|
|
Goto Forum:
Current Time: Tue Jul 22 15:30:07 EDT 2025
Powered by FUDForum. Page generated in 0.09856 seconds
|