Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Row remains highlighted after delete item in TableViewer
Row remains highlighted after delete item in TableViewer [message #821823] Thu, 15 March 2012 21:32 Go to next message
George R Malary is currently offline George R MalaryFriend
Messages: 36
Registered: March 2012
Location: New Jersey
Member
This is my first topic, so please bear with me :d

Using the TableViewer, I select a row, it highlights, and then we click an icon to delete the item from our database. I then set the TableViewer input to an updated list from the database. Row is deleted, and viewer displays the correct list, but the row of the deleted item remains highlighted, and cannot be deselected.

Below is code. Code of interest is createViewer() where we add the listener for when the delete icon is clicked, and then method deleteNode() is called.

I have tried deleting and deselecting the selected item from viewer.getTable(). I'm still not sure the underlying cause of why the row remains highlighted after I reset the viewer input. Attached is the table and the highlighted row after deletion.



private Table table;

/**
* @param parent
* parent
* @param style
* style
* @param workbenchPartSite
* getSite(), if not null
*/
public NodeOverviewComposite(final Composite parent, final int style,
final IWorkbenchSite workbenchPartSite) {
super(parent, style);
partSite = workbenchPartSite;

GridLayout layout = new GridLayout();
setLayout(layout);
createViewer(this);

if (partSite != null) {
makeActions();
// Used for popup menu when right click on table.
// hookContextMenu();
contributeToActionBars();
}

}

/**
* @param parent
* parent composite for viewer.
*/
private void createViewer(final Composite parent) {
viewer = new XSBTableViewer(this.getClass(), "nodeListTableViewer",
parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL
| SWT.FULL_SELECTION | SWT.BORDER);

createColumns(parent, viewer);

table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
createColumnsWeigthData(table);

viewer.setContentProvider(new ArrayContentProvider());
if (nodeModelProvider.getNodes().size() != 0) {
viewer.setInput(nodeModelProvider.getNodes());
}

viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
Table table = ((TableViewer) event.getSource()).getTable();
Point pt = table.toControl(Display.getCurrent()
.getCursorLocation());

TableItem item = table.getItem(pt);
if (item != null) {
if (item.getBounds(EDIT_COLUMN_INDEX).contains(pt)) {
// Place holder until we have an edit node dialog.
showMessage(
Messages.get().EditNodeDialog_dialog_title,
NLS.bind(
Messages.get().EditNodeDialog_dialog_message,
item.getText(HOSTNAME_COLUMN_INDEX)));
} else if (item.getBounds(DELETE_COLUMN_INDEX).contains(pt)) {
XSBMessageDialog deleteNodeDialog = new XSBMessageDialog(
parent.getShell(),
Messages.get().DeleteNodeDialog_dialog_title,
NLS.bind(
Messages.get().DeleteNodeDialog_dialog_message,
item.getText(HOSTNAME_COLUMN_INDEX)),
MessageDialog.WARNING,
new String[] {
Messages.get().DeleteNodeDialog_btn_delete,
Messages.get().DeleteNodeDialog_btn_cancel });
int deleteReturnCode = deleteNodeDialog.open();
// 0 if delete pressed, 1 is do no delete pressed.
if (deleteReturnCode == 0) {
deleteNode(event.getSelection());
}

}
}

}
});

if (partSite != null) {
// Make the selection available to other views
partSite.setSelectionProvider(viewer);
}

// Layout the viewer
GridData gridData = new GridData(GridData.FILL_BOTH);
viewer.getControl().setLayoutData(gridData);
}

/**
* This will create the columns for the table.
*
* @param parent
* parent composite for the table.
* @param viewer
* table viewer for the columns.
*/
private void createColumns(final Composite parent, final TableViewer viewer) {

// First column is for the node hostname.
TableViewerColumn col = createTableViewerColumn(HOSTNAME_COLUMN_TITLE);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
NodeDTO p = (NodeDTO) element;
return p.getNodeAddress();
}
});

// Second column is for the node type.
col = createTableViewerColumn(NODE_TYPE_COLUMN_TITLE);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
NodeDTO p = (NodeDTO) element;
return E_NodeTypes.getTypeByInt(p.getType());
}
});

// Third column is for the username.
col = createTableViewerColumn(USERNAME_COLUMN_TITLE);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(final Object element) {
NodeDTO p = (NodeDTO) element;
return p.getUserName();
}
});

// Fourth column is for the edit icon.
col = createTableViewerColumn(EDIT_COLUMN_TITLE);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(final Object element) {
return Activator.getDefault().getImageRegistry()
.get(IImageKeys.ICON_EDIT);
}

@Override
public String getText(final Object element) {
return "";
}
});
col.getColumn().setText("");
col.getColumn().setMoveable(false);
col.getColumn().setResizable(false);

// Fifth column is for the delete icon.
col = createTableViewerColumn(DELETE_COLUMN_TITLE);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(final Object element) {
return Activator.getDefault().getImageRegistry()
.get(IImageKeys.ICON_TRASH);
}

@Override
public String getText(final Object element) {
return "";
}
});
col.getColumn().setText("");
col.getColumn().setMoveable(false);
col.getColumn().setResizable(false);

}

/**
* Sets the column weights.
*
* @param table
* table for the node list data.
*/
public void createColumnsWeigthData(Table table) {
TableLayout layout = new TableLayout();
layout.addColumnData(new ColumnWeightData(4, 100, true));
layout.addColumnData(new ColumnWeightData(8, 100, true));
layout.addColumnData(new ColumnWeightData(4, 100, true));
layout.addColumnData(new ColumnWeightData(1, 30, false));
layout.addColumnData(new ColumnWeightData(1, 30, false));
table.setLayout(layout);

}

/**
* @param title
* title of column.
* @return Table Viewer Column
*/
private TableViewerColumn createTableViewerColumn(final String title) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
column.setText(title);
// column.setWidth(bound);
column.setResizable(true);
column.setMoveable(true);
column.setData(WidgetUtil.CUSTOM_WIDGET_ID,
"Column_" + title.replaceAll(" ", ""));
return viewerColumn;
}

/**
* Setup the action bars for menu and toobar.
*/
private void contributeToActionBars() {
IActionBars bars = ((IViewSite) partSite).getActionBars();
fillLocalPullDown(bars.getMenuManager());
fillLocalToolBar(bars.getToolBarManager());
}

/**
* Adds the actions to the menu.
*
* @param manager
* menu manager
*/
private void fillLocalPullDown(final IMenuManager manager) {
manager.add(addNodeAction);
}

/**
* Adds the actions to the toolbar of the viewer..
*
* @param manager
* menu manager
*/
private void fillLocalToolBar(final IToolBarManager manager) {
manager.add(addNodeAction);
}

/**
* Creates the actions. Currently only add node actions defined for viewer.
*/
private void makeActions() {
addNodeAction = new Action() {
public void run() {
AddNodeDialog addNodeDialog = new AddNodeDialog(partSite
.getWorkbenchWindow().getShell(),
Messages.get().AddNodeDialog_dialog_title,
nodeModelProvider);
if (addNodeDialog.open() == Window.OK) {
if (nodeModelProvider.getNodes().size() != 0) {
viewer.setInput(nodeModelProvider.getNodes());
}
viewer.refresh();
showMessage(
Messages.get().MessageDialog_ConfirmAddNode_title,
Messages.get().MessageDialog_ConfirmAddNode_message);
}
}
};
addNodeAction.setText("Add Node");
addNodeAction.setToolTipText("Add Node");
addNodeAction.setImageDescriptor(PlatformUI.getWorkbench()
.getSharedImages()
.getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
}

/**
* Takes the selection from the tableviewer and casts to NodeDTO. Attempts
* to delete NodeDTO. The resets input of the tableviewer to the new list of
* nodes.
*
* @param selection
* node selected from the table viewer.
* @return true if node deleted. false otherwise.
*/
public final boolean deleteNode(final ISelection selection) {
boolean nodeDeleted = false;

if (selection != null && selection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) selection;
NodeDTO selectedNode = (NodeDTO) sel.iterator().next();

nodeDeleted = nodeModelProvider.deleteNode(selectedNode
.getNodeName());

viewer.setInput(nodeModelProvider.getNodes());

if (nodeDeleted) {
showMessage(
Messages.get().MessageDialog_ConfirmDeleteNode_title,
NLS.bind(
Messages.get().MessageDialog_ConfirmDeleteNode_message,
selectedNode.getNodeAddress()));
} else {
showMessage(
Messages.get().MessageDialog_ConfirmDeleteNode_title,
NLS.bind(
Messages.get().MessageDialog_ConfirmDeleteNode_failed_message,
selectedNode.getNodeAddress()));
}

}

return nodeDeleted;
}



begin 644 TableScreeshot.png
MB5!.1PT*&@H````-24A$4@```H````'@"`8````UT=SD`````7-21T(`KLX<
MZ0````9B2T=$`/\`_P#_H+VGDP````EP2%ES```+$P``"Q,!`)J<&`````=T
M24U%!]P##Q4?`H]2$EL``!C?241!5'C:[=UKC)3U_?_A]Y[%!1906`Z"V@"M
M'*1002BI-CZ@C=B:&FLKM371MHFQ,9A4;6L3B4U:VQ@;$XU::U--8Q.UIO;7
M4JL)K593JQQLP`-6$5<7!&%=#GN:W9WY/_AG)RR"8@799:\KV0C#N#.Y]SN?
M^W7?,[-342J52@$`8,BHM`D```0@```"$````0@`@``$`$```@`@``$`$(``
M``A````$(````A````$(`(``!`!```(`"$````0@```"$````0@`@``$`$``
M`@`@``$`$(````A````$(````A````$(`(``!`!```(`"$````0@```"$```
M`0@`@``$`$```@`@``$`$(````A````$(````A````$(`(``!``0@```"$``
M``0@```"$````0@`@``$`$```@`@``$`$(````A````$(````A````$(`(``
M!``0@```"$````0@```"$````0@`@``$`$```@`@``$`$(````A````$(```
M`A````$(`"```0`0@```"$````0@```"$````0@`@``$`$```@`@``$`$(``
M``A````$(````A````$(`"```0`0@```"$````0@```"$````0@`@``$`$``
M`@`@``$`$(````A````$(````A````$(`"```0`0@```"$````0@```"$```
M`0@`@``$`$```@`@``$`$(````A````$(````A``0``"`"```0`0@```"$``
M``0@```"$````0@`@``$`$```@`@``$`$(````A````$(````A``0``"`"``
M`0`0@```"$````0@```"$````0@`@``$`$```@!PN`)PX\:-^=+OU]L2``!#
M1/6^?WGYY9=3*!126UMKRP``#(4`[.[NSNFGGVZK```<P_J]!M"9/P"`(1:`
M```(0```CC'5'W2%5:M6V4H``$,I`)-D\>+%MA0#SI8M6S)QXD0;`N`09^;D
MR9/3V]MK8W!H`5@JE6PI!B1K$^##S4QSD\1K``$`AAQG`!GT1[,`F)L(0`PR
M``XR,\U-$D\!`P`,.<X`,NB/9@$P-Q&`&&0`'&1FFILDG@(&`!ARG`%DT!_-
M`G#H,]/<Y$,%X-MOOYU;;KDEO_C%+\J7KUV[-D\\\42NOOKJ#WW#SS[[;!8L
M6-#OLK???CM77WUUKK_^^LR:-2M)LFG3ICSRR"/_TVTP-(;9X5HWUUY[;7[T
M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$(````A````$(````A````$(`(``!`!```(`(``!`!"````"$````0@`
M@``$`$```@`@``$`$(````A````$(````A````$(`(``!`!```(`(``!``0@
M```"$````0@`@``$`$```@`@``$`$(````A````$(````A````$(`(``!`!`
M``(`(``!``0@```"$````0@`@``$`$```@`@``$`$(````A````$(````A``
M``$(`(``!`!```(`"$````0@```"$````0@`@``$`$```@`@``$`$(````A`
M```$(````A````$(`(``!`!```(`"$````0@```"$````0@`@``$`$```@`@
M``$`$(````A````$(````A````$(`(``!`!```(`"$````0@```"$````0@`
M@``$`$```@`@``$`$(````A````$(````A````$(`(``!``0@```"$````0@
M```"$````0@`@``$`&"@J"B52B6;`0!@Z'`&$`!```(`(``!`!"````(0```
M!"````(0```!"`"```0`0``"`"```0`0@```"$````0@`(``!`!```(`(``!
M`!"````(0```!"````(0```!"`"```0`0``"`"```0`0@```"$````0@`(``
M!`!```(`(``!`!"````(0```!"````(0```!"`"```0`0``"`"```0`0@```
M"$````$(`(``!`!```(`(``!`!"````(0```!"````(0```!"`"```0`0``"
M`"```0`0@```"$````$(`(``!`!```(`(``!`!"````(0```!"````(0```!
M"`"```0`0``"`"```0`0@````A````$(`(``!`!```(`(``!`!"````(0```
M!"````(0```!"`"```0`0``"`"```0`0@````A````$(`(``!`!```(`(``!
M`!"````(0```!"````(0```!"`"```0`0``"`"```0`0@````A````$(`(``
M!`!```(`(``!`!"````(0```!"````(0```!"`"```0`0``"`"```0`$(```
M`A````$(`(``!`!```(`(``!`!"````(0```!"````(0```!"`"```0`0``"
M`"```0`$(````A````$(`(``!`!```(`(``!`!"````(0```CJ#_!\I-QS$6
/%<K``````$E%3D2N0F""
`
end
Re: Row remains highlighted after delete item in TableViewer [message #821836 is a reply to message #821823] Thu, 15 March 2012 21:55 Go to previous message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 1856
Registered: July 2009
Senior Member
Hi George,
I remember that we had a bug opened (already fixed) for this issue, but
I can't find it right now. Which version of RAP are you using?
Best,
Ivan

On 3/15/2012 11:32 PM, George R Malary wrote:
> This is my first topic, so please bear with me :d
>
> Using the TableViewer, I select a row, it highlights, and then we click an icon to delete the item from our database. I then set the TableViewer input to an updated list from the database. Row is deleted, and viewer displays the correct list, but the row of the deleted item remains highlighted, and cannot be deselected.
>
> Below is code. Code of interest is createViewer() where we add the listener for when the delete icon is clicked, and then method deleteNode() is called.
>
> I have tried deleting and deselecting the selected item from viewer.getTable(). I'm still not sure the underlying cause of why the row remains highlighted after I reset the viewer input. Attached is the table and the highlighted row after deletion.
>
>
>
> private Table table;
>
> /**
> * @param parent
> * parent
> * @param style
> * style
> * @param workbenchPartSite
> * getSite(), if not null
> */
> public NodeOverviewComposite(final Composite parent, final int style,
> final IWorkbenchSite workbenchPartSite) {
> super(parent, style);
> partSite = workbenchPartSite;
>
> GridLayout layout = new GridLayout();
> setLayout(layout);
> createViewer(this);
>
> if (partSite != null) {
> makeActions();
> // Used for popup menu when right click on table.
> // hookContextMenu();
> contributeToActionBars();
> }
>
> }
>
> /**
> * @param parent
> * parent composite for viewer.
> */
> private void createViewer(final Composite parent) {
> viewer = new XSBTableViewer(this.getClass(), "nodeListTableViewer",
> parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL
> | SWT.FULL_SELECTION | SWT.BORDER);
>
> createColumns(parent, viewer);
>
> table = viewer.getTable();
> table.setHeaderVisible(true);
> table.setLinesVisible(true);
> createColumnsWeigthData(table);
>
> viewer.setContentProvider(new ArrayContentProvider());
> if (nodeModelProvider.getNodes().size() != 0) {
> viewer.setInput(nodeModelProvider.getNodes());
> }
>
> viewer.addSelectionChangedListener(new ISelectionChangedListener() {
> @Override
> public void selectionChanged(final SelectionChangedEvent event) {
> Table table = ((TableViewer) event.getSource()).getTable();
> Point pt = table.toControl(Display.getCurrent()
> .getCursorLocation());
>
> TableItem item = table.getItem(pt);
> if (item != null) {
> if (item.getBounds(EDIT_COLUMN_INDEX).contains(pt)) {
> // Place holder until we have an edit node dialog.
> showMessage(
> Messages.get().EditNodeDialog_dialog_title,
> NLS.bind(
> Messages.get().EditNodeDialog_dialog_message,
> item.getText(HOSTNAME_COLUMN_INDEX)));
> } else if (item.getBounds(DELETE_COLUMN_INDEX).contains(pt)) {
> XSBMessageDialog deleteNodeDialog = new XSBMessageDialog(
> parent.getShell(),
> Messages.get().DeleteNodeDialog_dialog_title,
> NLS.bind(
> Messages.get().DeleteNodeDialog_dialog_message,
> item.getText(HOSTNAME_COLUMN_INDEX)),
> MessageDialog.WARNING,
> new String[] {
> Messages.get().DeleteNodeDialog_btn_delete,
> Messages.get().DeleteNodeDialog_btn_cancel });
> int deleteReturnCode = deleteNodeDialog.open();
> // 0 if delete pressed, 1 is do no delete pressed.
> if (deleteReturnCode == 0) {
> deleteNode(event.getSelection());
> }
>
> }
> }
>
> }
> });
>
> if (partSite != null) {
> // Make the selection available to other views
> partSite.setSelectionProvider(viewer);
> }
>
> // Layout the viewer
> GridData gridData = new GridData(GridData.FILL_BOTH);
> viewer.getControl().setLayoutData(gridData);
> }
>
> /**
> * This will create the columns for the table.
> *
> * @param parent
> * parent composite for the table.
> * @param viewer
> * table viewer for the columns.
> */
> private void createColumns(final Composite parent, final TableViewer viewer) {
>
> // First column is for the node hostname.
> TableViewerColumn col = createTableViewerColumn(HOSTNAME_COLUMN_TITLE);
> col.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(final Object element) {
> NodeDTO p = (NodeDTO) element;
> return p.getNodeAddress();
> }
> });
>
> // Second column is for the node type.
> col = createTableViewerColumn(NODE_TYPE_COLUMN_TITLE);
> col.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(final Object element) {
> NodeDTO p = (NodeDTO) element;
> return E_NodeTypes.getTypeByInt(p.getType());
> }
> });
>
> // Third column is for the username.
> col = createTableViewerColumn(USERNAME_COLUMN_TITLE);
> col.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public String getText(final Object element) {
> NodeDTO p = (NodeDTO) element;
> return p.getUserName();
> }
> });
>
> // Fourth column is for the edit icon.
> col = createTableViewerColumn(EDIT_COLUMN_TITLE);
> col.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public Image getImage(final Object element) {
> return Activator.getDefault().getImageRegistry()
> .get(IImageKeys.ICON_EDIT);
> }
>
> @Override
> public String getText(final Object element) {
> return "";
> }
> });
> col.getColumn().setText("");
> col.getColumn().setMoveable(false);
> col.getColumn().setResizable(false);
>
> // Fifth column is for the delete icon.
> col = createTableViewerColumn(DELETE_COLUMN_TITLE);
> col.setLabelProvider(new ColumnLabelProvider() {
> @Override
> public Image getImage(final Object element) {
> return Activator.getDefault().getImageRegistry()
> .get(IImageKeys.ICON_TRASH);
> }
>
> @Override
> public String getText(final Object element) {
> return "";
> }
> });
> col.getColumn().setText("");
> col.getColumn().setMoveable(false);
> col.getColumn().setResizable(false);
>
> }
>
> /**
> * Sets the column weights.
> *
> * @param table
> * table for the node list data.
> */
> public void createColumnsWeigthData(Table table) {
> TableLayout layout = new TableLayout();
> layout.addColumnData(new ColumnWeightData(4, 100, true));
> layout.addColumnData(new ColumnWeightData(8, 100, true));
> layout.addColumnData(new ColumnWeightData(4, 100, true));
> layout.addColumnData(new ColumnWeightData(1, 30, false));
> layout.addColumnData(new ColumnWeightData(1, 30, false));
> table.setLayout(layout);
>
> }
>
> /**
> * @param title
> * title of column.
> * @return Table Viewer Column
> */
> private TableViewerColumn createTableViewerColumn(final String title) {
> final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
> SWT.NONE);
> final TableColumn column = viewerColumn.getColumn();
> column.setText(title);
> // column.setWidth(bound);
> column.setResizable(true);
> column.setMoveable(true);
> column.setData(WidgetUtil.CUSTOM_WIDGET_ID,
> "Column_" + title.replaceAll(" ", ""));
> return viewerColumn;
> }
>
> /**
> * Setup the action bars for menu and toobar.
> */
> private void contributeToActionBars() {
> IActionBars bars = ((IViewSite) partSite).getActionBars();
> fillLocalPullDown(bars.getMenuManager());
> fillLocalToolBar(bars.getToolBarManager());
> }
>
> /**
> * Adds the actions to the menu.
> *
> * @param manager
> * menu manager
> */
> private void fillLocalPullDown(final IMenuManager manager) {
> manager.add(addNodeAction);
> }
>
> /**
> * Adds the actions to the toolbar of the viewer..
> *
> * @param manager
> * menu manager
> */
> private void fillLocalToolBar(final IToolBarManager manager) {
> manager.add(addNodeAction);
> }
>
> /**
> * Creates the actions. Currently only add node actions defined for viewer.
> */
> private void makeActions() {
> addNodeAction = new Action() {
> public void run() {
> AddNodeDialog addNodeDialog = new AddNodeDialog(partSite
> .getWorkbenchWindow().getShell(),
> Messages.get().AddNodeDialog_dialog_title,
> nodeModelProvider);
> if (addNodeDialog.open() == Window.OK) {
> if (nodeModelProvider.getNodes().size() != 0) {
> viewer.setInput(nodeModelProvider.getNodes());
> }
> viewer.refresh();
> showMessage(
> Messages.get().MessageDialog_ConfirmAddNode_title,
> Messages.get().MessageDialog_ConfirmAddNode_message);
> }
> }
> };
> addNodeAction.setText("Add Node");
> addNodeAction.setToolTipText("Add Node");
> addNodeAction.setImageDescriptor(PlatformUI.getWorkbench()
> .getSharedImages()
> .getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
> }
>
> /**
> * Takes the selection from the tableviewer and casts to NodeDTO. Attempts
> * to delete NodeDTO. The resets input of the tableviewer to the new list of
> * nodes.
> *
> * @param selection
> * node selected from the table viewer.
> * @return true if node deleted. false otherwise.
> */
> public final boolean deleteNode(final ISelection selection) {
> boolean nodeDeleted = false;
>
> if (selection != null&& selection instanceof IStructuredSelection) {
> IStructuredSelection sel = (IStructuredSelection) selection;
> NodeDTO selectedNode = (NodeDTO) sel.iterator().next();
>
> nodeDeleted = nodeModelProvider.deleteNode(selectedNode
> .getNodeName());
>
> viewer.setInput(nodeModelProvider.getNodes());
>
> if (nodeDeleted) {
> showMessage(
> Messages.get().MessageDialog_ConfirmDeleteNode_title,
> NLS.bind(
> Messages.get().MessageDialog_ConfirmDeleteNode_message,
> selectedNode.getNodeAddress()));
> } else {
> showMessage(
> Messages.get().MessageDialog_ConfirmDeleteNode_title,
> NLS.bind(
> Messages.get().MessageDialog_ConfirmDeleteNode_failed_message,
> selectedNode.getNodeAddress()));
> }
>
> }
>
> return nodeDeleted;
> }
>
>
>

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:Auto-refreshing ViewPart by using Job
Next Topic:Problems at RAP installation in Eclipse IDE 3.5
Goto Forum:
  


Current Time: Thu Nov 27 08:35:56 GMT 2014

Powered by FUDForum. Page generated in 0.02478 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software