Eclipse RCP - How to create and open View programmatically? - java

I want to open a View which includes table when operation is executed.
I can open view by viewId by that code:
display.asyncExec(new Runnable(){
public void run() {
ApplicationGIS.getView(true, viewId);
}});
This view's id defined on plugin.xml but I have to pass some parameters to the table on this view. I can create my custom view programatically but this time i can't open it becuase I don't have its id. Here is my view class:
public class MyCustomView extends ViewPart {
private Text text;
private Table table;
private TableViewer tableViewer;
#Override
public void createPartControl(Composite parent) {
// TODO Auto-generated method stub
parent.setLayout(new GridLayout(4, false));
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
composite.setLayout(new GridLayout(2, false));
text = new Text(composite, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Composite composite_1 = new Composite(composite, SWT.NONE);
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
GridLayout gl_composite_1 = new GridLayout(1, false);
gl_composite_1.horizontalSpacing = 0;
gl_composite_1.marginHeight = 0;
gl_composite_1.marginWidth = 0;
gl_composite_1.verticalSpacing = 0;
composite_1.setLayout(gl_composite_1);
tableViewer = new TableViewer(composite_1, SWT.BORDER | SWT.FULL_SELECTION);
table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
}
#Override
public void setFocus() {
// TODO Auto-generated method stub
}
}
So how can I access this programmatically created view and open it?

In Eclipse 3.x you can open a View like this:
MyView view = (MyView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(viewer_ID);
Or if you are implementing a command handler, you can call:
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
To set some content you can simply add a method like void setInput(MyContent input) to your ViewPart and pass the needed arguments to this method, after opening it.

I had the exact same problem. I wanted to create additional views from the one registered in the plugin. These URL's will get you what you want:
http://wiki.eclipse.org/FAQ_How_do_I_open_multiple_instances_of_the_same_view
http://www.java-tips.org/other-api-tips/eclipse/how-to-create-multiple-instances-of-one-viewpart.html
PlatformUI.getWorkbench().getActiveWorkbenchWindow().
getActivePage().showView(String viewID,String secondaryID,int Mode);

From #Chriss answer;
I added a method setInput(parameter) to my view and then I can pass my values to my custom view like this
MyCustomView view = new MyCustomView();
view.setInput(parameter);
display.asyncExec(new Runnable(){
public void run() {
ApplicationGIS.getView(true, viewId);
}});
and this works.

Related

Using StackLayout i want to show only one table on selection of flag

I have two tables, on flag i need to show one table at a time. My createControl() method is called at the time of loading and flag value is true so one table is loaded first time, when choose of false flag my second table its giving null pointer. because second time table is not called correctly. i seen in google that stacklayout will work for this type of loading which will load two table at the time of load. but i am not able to call them using stacklayout.
public void createControl(final Composite parent) {
final Font font = parent.getFont();
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
composite.setFont(font);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
final Composite controlsComposite = WidgetFactory.getClassicToolkit().createComposite(composite);
final GridLayout gridLayout = new GridLayout(NUM_COLUMN, false);
controlsComposite.setLayout(gridLayout);
final GridData gridData = new GridData(SWT.FILL, SWT.DEFAULT, true, true);
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
controlsComposite.setLayoutData(gridData);
if (getWizard() instanceof TestWizard) {
final IWizardPage[] wizardPages = getWizard().getPages();
for (final IWizardPage page : wizardPages) {
if (page instanceof PSRDesignerImportWizardPage) {
TestWizard importwizardPage = (TestWizard) page;
if (importwizardPage.isInitiative()) {
setTitle("Table1");
setMessage("Hello");
gridLayout.numColumns = 1;
controlsComposite.setLayout(gridLayout);
createTable1Control(controlsComposite);
gnerImport = true;
} else {
setTitle("Table2");
setMessage("Bye");
controlsComposite.setLayout(gridLayout);
createTable2Control(controlsComposite);
rDomainImport = true;
}
}
}
} else {
creatFileSelectionGroup(controlsComposite);
}
createImportOptions(controlsComposite);
setControl(composite);
}
code 2:
#Override
public IWizardPage getNextPage() {
List<tualInitiative> ualInitiativeList = getConceptualInitiativeList(psrUserInfo);
if (ualInitiativeList.isEmpty()) {
return null;
}
IWizardPage nextPage = super.getNextPage();
if (nextPage instanceof FormatImportWizardPage) {
FormatImportWizardPage xfPage = (FormatImportWizardPage) nextPage;
if (initiative) {
xfPage.settable1Data(ualInitiativeList);
} else {
xfPage.settable2Data(ualInitiativeList);
}
}
return nextPage;
}

How to display a composite on the top of another composite which contains a table viewer?

In the createControl(parent) method of the Wizard Page, the code is as below-
top = new Composite(parent, SWT.NONE);
top.setLayout(new FillLayout());
setControl(top);
setPageComplete(false);
createViewer(top);
I want to add a row above the composite denoted by top.
It doesn't allows me. If I add it, the composite denoted by top gets lost.
The below is rendered for the top composite -
The moment I place the below code before the top composite, the top composite gets lost -
upper = new Composite(parent, SWT.NONE);
upper.setLayout(new FillLayout());
setControl(upper);
Label label = new Label(page, SWT.NONE);
label.setText("Some text to disply");
Please suggest on how to achieve the same.
The below is the createControl snippet in my case. It breaks the scrolling and size of the table viewer if add a row.
#Override
public void createControl(Composite parent) {
/*top = new Composite(parent, SWT.NONE);
top.setLayout(new FillLayout());
setControl(top);*/
setPageComplete(false);
top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);
Label label = new Label(top, SWT.NONE);
label.setText("Some text to disply");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
createViewer(top);
}
private void createViewer(Composite parent) {
tableLayout = new TableColumnLayout();
// A separate composite containing just the table viewer is required
Composite tableComp = new Composite(parent, SWT.NONE);
tableComp.setLayout(tableLayout);
viewer = new TableViewer(tableComp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
createColumns(parent, viewer);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
}
public TableViewer getViewer() {
return viewer;
}
// This will create the columns for the table
private void createColumns(final Composite parent, final TableViewer viewer) {
String[] titles = { "Node Status", "Node Type", "Node Name" };
int[] bounds = { 100, 100, 100 };
Image HEADER = CommonUtility.HEADER;
TableViewerColumn col = null;
// First column is for type
col = createTableViewerColumn(HEADER, titles[0], bounds[0], 0);
col.setLabelProvider(new CentredImageCellLabelProvider() {
#Override
public Image getImage(Object element) {
GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
if (model.isNew()) {
return CommonUtility.CHECKED;
} else {
return CommonUtility.UNCHECKED;
}
}
});
// Weight for column
tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(50));
// now the newly created
col = createTableViewerColumn(HEADER, titles[1], bounds[1], 1);
col.setLabelProvider(new CentredImageCellLabelProvider() {
#Override
public Image getImage(Object element) {
GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
if ("ns_flow".equals(model.getIcon())) {
return CommonUtility.FLOW_SERVICE;
}
if ("ns_open_interface".equals(model.getIcon())) {
return CommonUtility.FOLDER;
}
if ("ns_record".equals(model.getIcon())) {
return CommonUtility.DOCUMENT_TYPE;
}
if ("ns_package".equals(model.getIcon())) {
return CommonUtility.PACKAGE;
}
if("RestResource".equals(model.getIcon())){
return CommonUtility.RESTFUL_FOLDER;
}
return null;
}
});
// Weight for column
tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(50));
// First column is for the component name
col = createTableViewerColumn(HEADER, titles[2], bounds[2], 2);
col.setLabelProvider(new ColumnLabelProvider() {
#Override
public String getText(Object element) {
GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
return model.getComponentName();
}
});
// Weight for column
tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(100));
}
private TableViewerColumn createTableViewerColumn(Image image, String title, int bound, final int colNumber) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.LEAD);
final TableColumn column = viewerColumn.getColumn();
column.setImage(image);
column.setText(title);
column.setWidth(bound);
column.setResizable(true);
column.setMoveable(true);
column.setAlignment(SWT.CENTER);
return viewerColumn;
}
A wizard page must only have one top level composite. You can add multiple controls (including nested composites) to that composite.
So for a label above to table:
top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);
Label label = new Label(top, SWT.NONE);
label.setText("Some text to disply");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
TableViewer viewer = new TableViewer(top, .... flags
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

TabItem does not refresh when list of tabItem has changed in SWT

Below is my code, When button press I am changing the item1 list by using item1.setcontrol depends on my condition.
Composite is not refreshing, But when I click on Item2 tab and come back to Item1 tab... List is updated depends on condition.
Please let me know How to refresh the layout with out moving to other Tab item.
final Composite RightComposite = new Composite(paComposite, SWT.NONE);
RightComposite.setLayout(new GridLayout(1, false));
RightComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true));
Composite findComposite = new Composite(RightComposite, SWT.NONE);
findComposite.setLayout(new GridLayout(2, true));
findComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, false));
txt = new Text(findComposite, SWT.BORDER | SWT.WRAP | SWT.SINGLE);
txt.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, false));
txt.addListener(SWT.Verify, new Listener()
{
#Override
public void handleEvent(final Event e)
{
newString = ((Text) e.widget).getText();
}
});
btn = new Button(findTCComposite, SWT.NONE);
btn.setLayoutData(new GridData(SWT.BEGINNING, GridData.BEGINNING, false, false));
btn.setText("Find button");
final TabFolder tabFolder = new TabFolder(RightComposite, SWT.NONE);
tabFolder.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true));
final TabItem item1 = new TabItem(tabFolder, SWT.NONE);
item1.setText("Tab 1 ");
btn.addListener (SWT.Selection, new Listener()
{
public void handleEvent(Event e) {
if(!newString.isEmpty()){
item1.setControl(list1);
}
else
{
item1.setControl(list);
}
}
});
TabItem item2 = new TabItem(tabFolder, SWT.NONE);
Item2.setText("Tab 2");
RightComposite.layout();
Your problem is in the SWT's TabItem class, in the setControl() function. At the end of this function it makes an: oldControl.setVisible (false);
So in your situation the oldControl will be the same control you set (it you set it twice) and it will be hidden. To solve the problem you can modify the code as:
btn.addListener (SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (!newString.isEmpty()) {
item1.setControl(list1);
list1.setVisible(true);
} else {
item1.setControl(list);
list.setVisible(true);
}
}
});
Or another approach:
btn.addListener (SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (newString != null && !newString.isEmpty()) {
if (item1.getControl() != list1) {
item1.setControl(list1);
}
} else {
if (item1.getControl() != list) {
item1.setControl(list);
}
}
}
});
I hope this fits your needs.

JFace -SWT How to make TitleAreaDialog similaire to Eclipse one

I would design TitleAreaDialog similar to those Eclipse but without sucess, below there is two screenshot, Eclipse form and my own form,
i have problem to get the top and bottom separator, if you notice,Eclipse form don't gave a margin and the workspace have margin.
in my own form my separator have a margin
Eclipse Form :
http://farm8.staticflickr.com/7437/9075688435_d5c49770fa_b.jpg
My own Form
http://farm4.staticflickr.com/3688/9077919366_8c25c40a79_b.jpg
here is the source code of my class
public class CompteDialog extends TitleAreaDialog {
private Text idCompteText;
private Text libelleCompteText;
private Text ribCompteText;
private Text agenceCompteText;
public CompteDialog(Shell parentShell) {
super(parentShell);
}
#Override
public void create() {
super.create();
// Set the title
setTitle("Fiche comptes");
// Set the message
setMessage("Saisissez les informations relatives au compte",
IMessageProvider.INFORMATION);
}
#Override
protected Control createDialogArea(Composite parent) {
setTitleImage(ResourceManager.getPluginImage(
"dz.iaityahia.cieptalcars.matresorerie", "icons/wallet.png"));
GridLayout layout = new GridLayout();
layout.numColumns = 2;
parent.setLayout(layout);
// Champs ID
Label idCompteLabel = new Label(parent, SWT.NONE);
idCompteLabel.setText("Compte ID");
GridData gridData = new GridData(GridData.BEGINNING,
GridData.BEGINNING, true, false, 1, 1);
idCompteText = new Text(parent, SWT.BORDER);
idCompteText.setLayoutData(gridData);
idCompteText.setTextLimit(20);
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
// Champs libelle
Label libelleCompteLabel = new Label(parent, SWT.NONE);
libelleCompteLabel.setText("Libellé compte");
libelleCompteText = new Text(parent, SWT.BORDER);
libelleCompteText.setLayoutData(gridData);
// Champs Rib
Label ribCompteLabel = new Label(parent, SWT.NONE);
ribCompteLabel.setText("R.I.B");
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
ribCompteText = new Text(parent, SWT.BORDER);
ribCompteText.setLayoutData(gridData);
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
// Champs libelle
Label agenceCompteLabel = new Label(parent, SWT.NONE);
agenceCompteLabel.setText("Agence bancaire");
agenceCompteText = new Text(parent, SWT.BORDER);
agenceCompteText.setLayoutData(gridData);
// Create a bottom separator
Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true, 2, 1));
return parent;
}
#Override
protected Control createButtonBar(Composite parent) {
final Composite buttonBar = new Composite(parent, SWT.NONE);
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = false;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
buttonBar.setLayout(layout);
GridData gridData = new GridData(GridData.FILL, GridData.END, true,
true, 2, 1);
buttonBar.setLayoutData(gridData);
/*
* org.eclipse.swt.graphics.Color magenta =
* Display.getDefault().getSystemColor(SWT.COLOR_MAGENTA);
* buttonBar.setBackground(magenta);
*/
// Create Add button
// Own method as we need to overview the SelectionAdapter
createOkButton(buttonBar, OK, "Add", true);
// Add a SelectionListener
// Create Cancel button
Button cancelButton = createButton(buttonBar, CANCEL, "Cancel", false);
// Add a SelectionListener
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setReturnCode(CANCEL);
close();
}
});
return buttonBar;
}
protected Button createOkButton(Composite parent, int id, String label,
boolean defaultButton) {
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
button.setFont(JFaceResources.getDialogFont());
button.setData(new Integer(id));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (isValidInput()) {
okPressed();
}
}
});
if (defaultButton) {
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
}
setButtonLayoutData(button);
return button;
}
private boolean isValidInput() {
boolean valid = true;
if (idCompteText.getText().length() == 0) {
setErrorMessage("Veuillez saisir le compte ID");
valid = false;
}
if (libelleCompteText.getText().length() == 0) {
setErrorMessage("Veuillez saisir le libellé du compte");
valid = false;
}
return valid;
}
#Override
protected boolean isResizable() {
return true;
}
}
Could someone give me an idea how to get TiteAreaDialog similar to those of Eclipse ?
with my thank's
I finally solved the problem myself, after thoroughly looked at the code of the TitleAreaDilog class, I found that there was no way to do this directly.
with a little imagination I found the trick, it was necessary to create two nested Composites
the parent Composite without margin will contain the two separators and the child composite which have margin and will contain others controls.
as we you can see in the example below.
I hope this will help some beginners like me
package dz.iaityahia.cieptalcars.matresorerie.dialogs;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.ResourceManager;
public class CompteDialog extends TitleAreaDialog {
private Text idCompteText;
private Text libelleCompteText;
private Text ribCompteText;
private Text agenceCompteText;
public CompteDialog(Shell parentShell) {
super(parentShell);
setHelpAvailable(true);
// TODO Auto-generated constructor stub
}
#Override
public void create() {
super.create();
// Set the title
setTitle("Fiche comptes");
// Set the message
setMessage("Saisissez les informations relatives au compte",
IMessageProvider.INFORMATION);
setTitleImage(ResourceManager.getPluginImage("dz.iaityahia.cieptalcars.matresorerie", "icons/wallet.png"));
}
#Override
protected Control createDialogArea(Composite parent) {
// cr�ation du Layout du la boite de dialog
GridLayout parentLayout = new GridLayout();
parentLayout.numColumns=1;
parentLayout.marginWidth=0;
parentLayout.marginHeight=0;
parent.setLayout(parentLayout);
//Cr�ation du s�parateur sup�rieur
Label linetop = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
linetop.setLayoutData(new GridData (SWT.FILL,SWT.TOP,true,false));
//Cr�ation du composite contenu
Composite workArea = new Composite(parent, SWT.NONE);
workArea.setLayoutData(new GridData (SWT.FILL,SWT.FILL,true,true));
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth=10;
layout.marginHeight=10;
workArea.setLayout(layout);
// Champs ID
Label idCompteLabel = new Label(workArea,SWT.NONE);
idCompteLabel.setText("Compte ID");
idCompteText = new Text(workArea, SWT.BORDER);
idCompteText.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true,false,1, 1));
idCompteText.setTextLimit(20);
// Champs libelle
Label libelleCompteLabel = new Label(workArea,SWT.NONE);
libelleCompteLabel.setText("Libell� compte");
libelleCompteText = new Text(workArea, SWT.BORDER);
libelleCompteText.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true,false,1, 1));
// Champs Rib
Label ribCompteLabel = new Label(workArea,SWT.NONE);
ribCompteLabel.setText("R.I.B");
ribCompteText = new Text(workArea, SWT.BORDER);
ribCompteText.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true,false, 1, 1));
// Champs Agence bancaire
Label agenceCompteLabel = new Label(workArea,SWT.NONE);
agenceCompteLabel.setText("Agence bancaire");
agenceCompteText = new Text(workArea, SWT.BORDER);
agenceCompteText.setLayoutData( new GridData(GridData.FILL, GridData.BEGINNING, true,false, 1, 1));
return parent;
}
#Override
protected Control createButtonBar(Composite parent) {
Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
line.setLayoutData(new GridData (SWT.FILL,SWT.TOP,true,false));
final Composite buttonBar = new Composite(parent, SWT.NONE);
buttonBar.setLayoutData(new GridData (SWT.FILL,SWT.TOP,true,false));
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = false;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
buttonBar.setLayout(layout);
// Create Add button
// Own method as we need to overview the SelectionAdapter
createOkButton(buttonBar, OK, "Add", true);
// Add a SelectionListener
// Create Cancel button
Button cancelButton =
createButton(buttonBar, CANCEL, "Cancel", false);
// Add a SelectionListener
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setReturnCode(CANCEL);
close();
}
});
return buttonBar;
}

How to update/refresh a view in an eclipse plug-in?

I have an eclipse plug-in with a single view (like the eclipse helloworld-view-plugin-project). In the view-file I get an event when I want to update the view.
In this view I have a GridData in a Group with multiple labels. I have several services which register to the programe and whose status should be shown in this GridData.
Edit: In order to better show my problem I updated this post and added the whole code:
CreatePartControl():
public void createPartControl(Composite _parent) {
parent = _parent;
createContents();
addBindings();
makeActions();
contributeToActionBars();
}
CreateContents():
protected void createContents() {
// fixed
checkIcon = //...
errorIcon = //...
smallFont = SWTResourceManager.getFont("Segoe UI", 7, SWT.NORMAL);
// content
gl_shell = new GridLayout(1, false);
//margins, etc. for gl_shell
parent.setLayout(gl_shell);
final Label lblGreeting = new Label(parent, SWT.NONE);
lblGreeting.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
lblGreeting.setText("Hi " + Preferences.getPreName());
// -- GROUP YOUR STATS (show all services)
createStatusGroupBox();
}
createStatusGroupBox():
private Group grpYourStatus = null; // outside the method for access in listener (below)
private void createStatusGroupBox() {
grpYourStatus = new Group(parent, SWT.NONE);
grpYourStatus.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
grpYourStatus.setText("Your upload status");
grpYourStatus.setLayout(new GridLayout(3, false));
// add message if no service is registered
if ( r.getServiceList().size() == 0 ) {
Label status = new Label(grpYourStatus, SWT.NONE);
status.setText("No service registered.");
new Label(grpYourStatus, SWT.NONE); //empty
new Label(grpYourStatus, SWT.NONE); //empty
}
// add labels (status, message, name) for each registered service
for ( IRecorderObject service : r.getServiceList() ) {
Label name = new Label(grpYourStatus, SWT.NONE);
Label status = new Label(grpYourStatus, SWT.NONE);
Label message = new Label(grpYourStatus, SWT.NONE);
message.setFont(smallFont);
message.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
service.getServiceViewItem().setLabelsAndIcons(name, status, message, checkIcon, errorIcon); //this also sets the values of the labels (label.setText(...) via data binding)
}
Unfortunately, I don't know what the right way is to update/reset it. I tried the following:
listener (which should update the view / the services-list):
r.addPropertyChangeListener(BindingNames.SERVICE_ADDED, new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent evt) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// This "redraws" the view, but just places the whole content (generated in createStatusGroupBox()) above the other parts.
//Display.getCurrent().update();
//createStatusGroupBox();
//parent.layout(true);
//parent.redraw();
// disposes grpYourStatus-Group but doesn't show anything then
grpYourStatus.dispose();
createStatusGroupBox();
grpYourStatus.layout();
grpYourStatus.redraw();
}
});
}
});
I also tried the following statements (individually); all without success:
parent.redraw();
parent.update();
parent.layout();
parent.layout(true);
parent.refresh();
In this post I read the following:
createPartControls is that time of the life cycle of a view, where its
contained widgets are created (when the view becomes visible
initially). This code is only executed once during the view life
cycle, therefore you cannot add anything here directly to refresh your
view.
Eclipse parts typically update their content as a reaction to a
changed selection inside of the workbench (e.g. the user might click
on another stack frame in the debug view).
Unfortunately, I don't know what to else I could try and I didn't find anything helpful with searches... thank's for your help and suggestions!
I finally found the answer (together with AndreiC's help!):
my listener now looks like this:
r.addPropertyChangeListener(BindingNames.SERVICE_ADDED, new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent evt) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// remove grpYourStatus from parent
grpYourStatus.dispose();
// add grpYourStatus (with updated values) to parent
createStatusGroupBox();
// refresh view
parent.pack();
parent.layout(true);
}
});
}
});
The rest is the same like the code above.
I do not know the API by heart, but have you tried parent.update()?

Categories