use of org.obeonetwork.graal.UserStoryElement in project InformationSystem by ObeoNetwork.
the class UserStoriesView method createPartControl.
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
viewer = new CheckboxTreeViewer(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
viewer.setUseHashlookup(true);
viewer.setContentProvider(new UserStoriesContentProvider());
viewer.setLabelProvider(new UserStoryLabelProvider(this, adapterFactory));
viewer.setCheckStateProvider(new UserStoriesCheckStateProvider(viewer));
viewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
if (event.getElement() instanceof UserStory) {
UserStory story = (UserStory) event.getElement();
if (viewer.getInput() instanceof UserStoryElement) {
TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(viewer.getInput());
if (editingDomain != null) {
if (event.getChecked()) {
LinkStory command = new LinkStory(story, (UserStoryElement) viewer.getInput());
editingDomain.getCommandStack().execute(command);
} else {
UnlinkStory command = new UnlinkStory(story, (UserStoryElement) viewer.getInput());
editingDomain.getCommandStack().execute(command);
}
}
} else if (viewer.getInput() instanceof Collection<?>) {
List<UserStoryElement> selection = new ArrayList<UserStoryElement>();
for (Object next : (Collection<?>) viewer.getInput()) {
if (next instanceof UserStoryElement) {
selection.add((UserStoryElement) next);
}
}
if (!selection.isEmpty()) {
TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(selection.get(0));
if (editingDomain != null) {
if (event.getChecked()) {
LinkStory command = new LinkStory(story, selection);
editingDomain.getCommandStack().execute(command);
} else {
UnlinkStory command = new UnlinkStory(story, selection);
editingDomain.getCommandStack().execute(command);
}
}
}
}
}
viewer.refresh();
}
});
ColumnViewerToolTipSupport.enableFor(viewer);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
State state = service.getCommand(HighlightUserStoryCommand.COMMAND_ID).getState(HighlightUserStoryCommand.STATE_ID);
state.setValue(getSelectedStories().size() == 1 && isActiveUserStory(getSelectedStories().get(0)));
service.refreshElements(HighlightUserStoryCommand.COMMAND_ID, null);
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
updateUserStoryHighlightment();
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
State state = service.getCommand(HighlightUserStoryCommand.COMMAND_ID).getState(HighlightUserStoryCommand.STATE_ID);
state.setValue(getSelectedStories().size() == 1 && isActiveUserStory(getSelectedStories().get(0)));
service.refreshElements(HighlightUserStoryCommand.COMMAND_ID, null);
}
});
getSite().setSelectionProvider(viewer);
selectionListener = new ViewpointMultiSelectionListener(this) {
@Override
protected void eObjectSelected(Session session, List<EObject> selectedEObjects) {
update(session, selectedEObjects);
}
};
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);
}
Aggregations