Search in sources :

Example 1 with UserStoryLabelProvider

use of org.obeonetwork.graal.design.ui.view.util.UserStoryLabelProvider 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);
}
Also used : LinkStory(org.obeonetwork.graal.design.command.LinkStory) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) UnlinkStory(org.obeonetwork.graal.design.command.UnlinkStory) ArrayList(java.util.ArrayList) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ICommandService(org.eclipse.ui.commands.ICommandService) UserStory(org.obeonetwork.graal.UserStory) UserStoriesContentProvider(org.obeonetwork.graal.design.ui.view.util.UserStoriesContentProvider) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) EObject(org.eclipse.emf.ecore.EObject) UserStoryLabelProvider(org.obeonetwork.graal.design.ui.view.util.UserStoryLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) UserStoriesCheckStateProvider(org.obeonetwork.graal.design.ui.view.util.UserStoriesCheckStateProvider) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) State(org.eclipse.core.commands.State) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) UserStoryElement(org.obeonetwork.graal.UserStoryElement) ViewpointMultiSelectionListener(org.obeonetwork.graal.design.ui.view.util.ViewpointMultiSelectionListener) Session(org.eclipse.sirius.business.api.session.Session)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 State (org.eclipse.core.commands.State)1 EObject (org.eclipse.emf.ecore.EObject)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 Session (org.eclipse.sirius.business.api.session.Session)1 ICommandService (org.eclipse.ui.commands.ICommandService)1 UserStory (org.obeonetwork.graal.UserStory)1 UserStoryElement (org.obeonetwork.graal.UserStoryElement)1 LinkStory (org.obeonetwork.graal.design.command.LinkStory)1 UnlinkStory (org.obeonetwork.graal.design.command.UnlinkStory)1 UserStoriesCheckStateProvider (org.obeonetwork.graal.design.ui.view.util.UserStoriesCheckStateProvider)1 UserStoriesContentProvider (org.obeonetwork.graal.design.ui.view.util.UserStoriesContentProvider)1