Home » Eclipse Projects » Remote Application Platform (RAP) » Row remains highlighted after delete item in TableViewer(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 dele)
Row remains highlighted after delete item in TableViewer [message #821820] |
Thu, 15 March 2012 21:32 |
George R Malary Messages: 36 Registered: March 2012 Location: New Jersey |
Member |
|
|
This is my first topic, so please bear with me
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;
}
|
|
| | | | | | | | | | |
Re: Row remains highlighted after delete item in TableViewer [message #822428 is a reply to message #822153] |
Fri, 16 March 2012 16:03 |
George R Malary Messages: 36 Registered: March 2012 Location: New Jersey |
Member |
|
|
Ok, I have this working, but am not clear as to why it works, and what the problem is. showMessage is just a mesage dialog saying the node had been deleted. Below is the code snippet that works:
if (nodeDeleted) {
viewer.setSelection(StructuredSelection.EMPTY);
showMessage(Messages.get().MessageDialog_ConfirmDeleteNode_title,
NLS.bind(Messages.get().MessageDialog_ConfirmDeleteNode_message,
selectedNode.getNodeAddress()));
viewer.setInput(nodeModelProvider.getNodesFromDB());
}
So when user click delete on the confirm message dialog, and delete is successful in the backend, the selection is cleared, but the item is still visible in the viewer in the background because I have not reset the input. The message dialog appears confirming deletion, and then the viewer input is reset, and the viewer is updated, and selections are all cleared as expected.
Ideally, I want to clear the selection and update the viewer before showing the message dialog confirming deletion, so that the user doesnt still see his selection in the background. But I try the following, and I get the same weird behavior where the row is deleted but stays highlighted.
if (nodeDeleted) {
viewer.setSelection(StructuredSelection.EMPTY);
viewer.setInput(nodeModelProvider.getNodesFromDB());
showMessage(Messages.get().MessageDialog_ConfirmDeleteNode_title,
NLS.bind(Messages.get().MessageDialog_ConfirmDeleteNode_message,
selectedNode.getNodeAddress()));
}
So I'm confused why it would work with the message dialog in between the setSelection and the setInput, and not when they are together. I also tried without the message dialog and the same error occurs. Seem buggy to me, unless I'm doing something wrong.
|
|
|
Re: Row remains highlighted after delete item in TableViewer [message #822431 is a reply to message #822153] |
Fri, 16 March 2012 16:03 |
George R Malary Messages: 36 Registered: March 2012 Location: New Jersey |
Member |
|
|
Ok, I have this working, but am not clear as to why it works, and what the problem is. showMessage is just a mesage dialog saying the node had been deleted. Below is the code snippet that works:
if (nodeDeleted) {
viewer.setSelection(StructuredSelection.EMPTY);
showMessage(Messages.get().MessageDialog_ConfirmDeleteNode_title,
NLS.bind(Messages.get().MessageDialog_ConfirmDeleteNode_message,
selectedNode.getNodeAddress()));
viewer.setInput(nodeModelProvider.getNodesFromDB());
}
So when user click delete on the confirm message dialog, and delete is successful in the backend, the selection is cleared, but the item is still visible in the viewer in the background because I have not reset the input. The message dialog appears confirming deletion, and then the viewer input is reset, and the viewer is updated, and selections are all cleared as expected.
Ideally, I want to clear the selection and update the viewer before showing the message dialog confirming deletion, so that the user doesnt still see his selection in the background. But I try the following, and I get the same weird behavior where the row is deleted but stays highlighted.
if (nodeDeleted) {
viewer.setSelection(StructuredSelection.EMPTY);
viewer.setInput(nodeModelProvider.getNodesFromDB());
showMessage(Messages.get().MessageDialog_ConfirmDeleteNode_title,
NLS.bind(Messages.get().MessageDialog_ConfirmDeleteNode_message,
selectedNode.getNodeAddress()));
}
So I'm confused why it would work with the message dialog in between the setSelection and the setInput, and not when they are together. I also tried without the message dialog and the same error occurs. Seem buggy to me, unless I'm doing something wrong.
|
|
|
Re: Row remains highlighted after delete item in TableViewer [message #822440 is a reply to message #822428] |
Fri, 16 March 2012 16:20 |
Ivan Furnadjiev Messages: 2426 Registered: July 2009 Location: Sofia, Bulgaria |
Senior Member |
|
|
Hi George,
as I mentioned before, there was a bug in the client-side Table (Tree)
implementation. See:
366272: [Tree] Full selection artifacts remain shown upon collapse of
tree node
https://bugs.eclipse.org/bugs/show_bug.cgi?id=366272
I think that this is the same issue. It has been fixed in 1.5M5. Which
RAP version are you using? Could you try your application with RAP 1.5M5
or latest nightly?
Best,
Ivan
On 3/16/2012 6:03 PM, George R Malary wrote:
> Ok, I have this working, but am not clear as to why it works, and what
> the problem is. showMessage is just a mesage dialog saying the node
> had been deleted. Below is the code snippet that works:
>
>
> if (nodeDeleted) {
> viewer.setSelection(StructuredSelection.EMPTY);
> showMessage(Messages.get().MessageDialog_ConfirmDeleteNode_title,
> NLS.bind(Messages.get().MessageDialog_ConfirmDeleteNode_message,
> selectedNode.getNodeAddress()));
> viewer.setInput(nodeModelProvider.getNodesFromDB());
> }
>
>
> So when user click delete on the confirm message dialog, and delete is
> successful in the backend, the selection is cleared, but the item is
> still visible in the viewer in the background because I have not reset
> the input. The message dialog appears confirming deletion, and then
> the viewer input is reset, and the viewer is updated, and selections
> are all cleared as expected.
>
> Ideally, I want to clear the selection and update the viewer before
> showing the message dialog confirming deletion, so that the user
> doesnt still see his selection in the background. But I try the
> following, and I get the same weird behavior where the row is deleted
> but stays highlighted.
>
>
> if (nodeDeleted) {
> viewer.setSelection(StructuredSelection.EMPTY);
> viewer.setInput(nodeModelProvider.getNodesFromDB());
> showMessage(Messages.get().MessageDialog_ConfirmDeleteNode_title,
> NLS.bind(Messages.get().MessageDialog_ConfirmDeleteNode_message,
> selectedNode.getNodeAddress()));
> }
>
>
> So I'm confused why it would work with the message dialog in between
> the setSelection and the setInput, and not when they are together. I
> also tried without the message dialog and the same error occurs. Seem
> buggy to me, unless I'm doing something wrong.
>
--
Ivan Furnadjiev
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
| | |
Goto Forum:
Current Time: Thu Apr 25 01:54:23 GMT 2024
Powered by FUDForum. Page generated in 0.03986 seconds
|