@Override public void modelChanged(IModelChangedEvent event) { if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { fHeader = null; markStale(); return; } if (getExportedPackageHeader().equals(event.getChangedProperty())) { refresh(); // Bug 171896 // Since the model sends a CHANGE event instead of // an INSERT event on the very first addition to the empty table // Selection should fire here to take this first insertion into account Object lastElement = fPackageViewer.getElementAt(fPackageViewer.getTable().getItemCount() - 1); if (lastElement != null) { fPackageViewer.setSelection(new StructuredSelection(lastElement)); } return; } Object[] objects = event.getChangedObjects(); for (Object changedObject : objects) { if (changedObject instanceof ExportPackageObject) { ExportPackageObject object = (ExportPackageObject) changedObject; switch (event.getChangeType()) { case IModelChangedEvent.INSERT: fPackageViewer.add(object); fPackageViewer.setSelection(new StructuredSelection(object), false); fPackageViewer.getTable().setFocus(); break; case IModelChangedEvent.REMOVE: Table table = fPackageViewer.getTable(); int index = table.getSelectionIndex(); fPackageViewer.remove(object); table.setSelection(index < table.getItemCount() ? index : table.getItemCount() - 1); break; default: fPackageViewer.refresh(object); } } } }
@Override public void refresh() { fPackageViewer.refresh(); super.refresh(); }