Search in sources :

Example 1 with PossibleStepEditPart

use of org.eclipse.gemoc.timeline.editpart.PossibleStepEditPart in project gemoc-studio by eclipse.

the class AbstractTimelineView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    final Composite container;
    if (hasDetailViewer()) {
        final SashForm mainSashForm = new SashForm(parent, SWT.HORIZONTAL);
        container = mainSashForm;
        detailViewer = createDetailViewer(container);
    } else {
        container = parent;
    }
    timelineViewer = new ScrollingGraphicalViewer();
    Composite timelineComposite = new Composite(container, SWT.NONE);
    timelineComposite.setLayout(new FillLayout(SWT.HORIZONTAL | SWT.VERTICAL));
    if (hasDetailViewer()) {
        ((SashForm) container).setWeights(new int[] { DETAIL_RATIO, TIMELINE_RATIO });
    }
    GridLayout layout = new GridLayout(1, false);
    timelineComposite.setLayout(layout);
    timelineViewer.createControl(timelineComposite);
    timelineSlider = new Slider(timelineComposite, SWT.HORIZONTAL);
    GridData gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    timelineSlider.setLayoutData(gridData);
    gridData.grabExcessHorizontalSpace = true;
    rootEditPart = new ScalableFreeformRootEditPart();
    rootEditPart.setViewer(timelineViewer);
    timelineViewer.setRootEditPart(rootEditPart);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.verticalAlignment = SWT.FILL;
    gridData.grabExcessVerticalSpace = true;
    timelineViewer.getControl().setLayoutData(gridData);
    timelineViewer.setEditPartFactory(getTimelineEditPartFactory());
    timelineWindow = new TimelineWindow(provider);
    timelineViewer.setContents(timelineWindow);
    timelineSlider.setPageIncrement(timelineWindow.getLength());
    timelineSlider.setThumb(timelineWindow.getLength());
    timelineSlider.setSelection(timelineWindow.getStart());
    if (provider != null) {
        timelineSlider.setMaximum(timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
        timelineSlider.setVisible(timelineWindow.getLength() < timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
    } else {
        timelineSlider.setVisible(false);
    }
    timelineSlider.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (follow) {
                toggleFollow();
            }
            timelineWindow.setStart(timelineSlider.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            if (follow) {
                toggleFollow();
            }
            timelineWindow.setStart(timelineSlider.getSelection());
        }
    });
    timelineWindowListener = new TimelineWindowListener();
    timelineWindow.addTimelineWindowListener(timelineWindowListener);
    if (provider != null) {
        provider.addTimelineListener(timelineWindowListener);
    }
    timelineViewer.getControl().setBackground(ColorConstants.listBackground);
    if (hasDetailViewer()) {
        timelineViewer.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                final ISelection selection = event.getSelection();
                if (selection instanceof IStructuredSelection) {
                    final Object firstElement = ((IStructuredSelection) selection).getFirstElement();
                    if (firstElement instanceof PossibleStepEditPart) {
                        final PossibleStepEditPart possibleStepEditPart = (PossibleStepEditPart) firstElement;
                        detailViewer.setInput(possibleStepEditPart.getModel().getPossibleStep());
                    }
                }
            }
        });
    }
    timelineViewer.getControl().addKeyListener(new TimelineKeyListener());
    final TimelineMouseListener listener = new TimelineMouseListener();
    timelineViewer.getControl().addMouseListener(listener);
    timelineViewer.getControl().addMouseMoveListener(listener);
    timelineViewer.getControl().addMouseWheelListener(new TimelineMouseWheelListener());
    rootEditPart.getZoomManager().addZoomListener(new ZoomListener() {

        @Override
        public void zoomChanged(double zoom) {
            timelineWindow.setLength(getWindowLength());
        }
    });
    timelineViewer.getControl().addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            timelineWindow.setLength(getWindowLength());
            final Canvas canevas = (Canvas) timelineViewer.getControl();
            canevas.getHorizontalBar().setVisible(false);
        }

        @Override
        public void controlMoved(ControlEvent e) {
        // nothing to do here
        }
    });
    final ICommandService cmdService = (ICommandService) getSite().getService(ICommandService.class);
    String commandID = getFollowCommandID();
    if (commandID != null) {
        final Command followCommand = cmdService.getCommand(commandID);
        if (followCommand != null) {
            final State state = followCommand.getState(RegistryToggleState.STATE_ID);
            follow = state != null && ((Boolean) state.getValue()).booleanValue();
        }
    }
    createMenuManager();
}
Also used : Slider(org.eclipse.swt.widgets.Slider) TimelineWindow(org.eclipse.gemoc.timeline.model.TimelineWindow) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICommandService(org.eclipse.ui.commands.ICommandService) ScrollingGraphicalViewer(org.eclipse.gef.ui.parts.ScrollingGraphicalViewer) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ControlListener(org.eclipse.swt.events.ControlListener) PossibleStepEditPart(org.eclipse.gemoc.timeline.editpart.PossibleStepEditPart) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FigureCanvas(org.eclipse.draw2d.FigureCanvas) Canvas(org.eclipse.swt.widgets.Canvas) FillLayout(org.eclipse.swt.layout.FillLayout) SashForm(org.eclipse.swt.custom.SashForm) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) Command(org.eclipse.core.commands.Command) State(org.eclipse.core.commands.State) RegistryToggleState(org.eclipse.ui.handlers.RegistryToggleState) ZoomListener(org.eclipse.gef.editparts.ZoomListener) GridData(org.eclipse.swt.layout.GridData) ControlEvent(org.eclipse.swt.events.ControlEvent) ITimelineWindowListener(org.eclipse.gemoc.timeline.model.ITimelineWindowListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

Command (org.eclipse.core.commands.Command)1 State (org.eclipse.core.commands.State)1 FigureCanvas (org.eclipse.draw2d.FigureCanvas)1 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)1 ZoomListener (org.eclipse.gef.editparts.ZoomListener)1 ScrollingGraphicalViewer (org.eclipse.gef.ui.parts.ScrollingGraphicalViewer)1 PossibleStepEditPart (org.eclipse.gemoc.timeline.editpart.PossibleStepEditPart)1 ITimelineWindowListener (org.eclipse.gemoc.timeline.model.ITimelineWindowListener)1 TimelineWindow (org.eclipse.gemoc.timeline.model.TimelineWindow)1 ISelection (org.eclipse.jface.viewers.ISelection)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SashForm (org.eclipse.swt.custom.SashForm)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ControlListener (org.eclipse.swt.events.ControlListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1