2015-11-15 22:15:37 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015 MINRES Technologies GmbH and others.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* MINRES Technologies GmbH - initial API and implementation
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.minres.scviewer.e4.application.elements;
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.inject.Named;
|
|
|
|
|
|
|
|
import org.eclipse.e4.core.di.annotations.Optional;
|
|
|
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
|
|
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
|
|
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
|
|
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
|
|
|
import org.eclipse.jface.viewers.ComboViewer;
|
|
|
|
import org.eclipse.jface.viewers.ISelection;
|
|
|
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
|
|
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
|
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|
|
|
import org.eclipse.jface.viewers.StructuredSelection;
|
|
|
|
import org.eclipse.swt.SWT;
|
|
|
|
import org.eclipse.swt.widgets.Combo;
|
|
|
|
import org.eclipse.swt.widgets.Composite;
|
|
|
|
|
|
|
|
import com.minres.scviewer.database.ITx;
|
|
|
|
import com.minres.scviewer.database.RelationType;
|
2017-01-23 22:53:14 +01:00
|
|
|
import com.minres.scviewer.e4.application.Messages;
|
2015-11-15 22:15:37 +01:00
|
|
|
import com.minres.scviewer.e4.application.parts.PartListener;
|
2015-11-22 12:47:07 +01:00
|
|
|
import com.minres.scviewer.e4.application.parts.WaveformViewer;
|
2015-11-15 22:15:37 +01:00
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* The Class RelationTypeToolControl allowing to control which TX relation is used for navigation.
|
|
|
|
*/
|
2015-11-15 22:15:37 +01:00
|
|
|
public class RelationTypeToolControl extends PartListener implements ISelectionChangedListener {
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The part service. */
|
2015-11-15 22:15:37 +01:00
|
|
|
EPartService partService;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The combo viewer. */
|
2015-11-15 22:15:37 +01:00
|
|
|
ComboViewer comboViewer;
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The waveform viewer part. */
|
|
|
|
WaveformViewer waveformViewerPart;
|
2015-11-15 22:15:37 +01:00
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/** The dummy. */
|
2017-01-23 22:53:14 +01:00
|
|
|
RelationType dummy = RelationType.create(Messages.RelationTypeToolControl_0);
|
2015-11-15 22:15:37 +01:00
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Instantiates a new relation type tool control.
|
|
|
|
*
|
|
|
|
* @param partService the part service
|
|
|
|
*/
|
2015-11-15 22:15:37 +01:00
|
|
|
@Inject
|
|
|
|
public RelationTypeToolControl(EPartService partService) {
|
|
|
|
this.partService=partService;
|
|
|
|
partService.addPartListener(this);
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Creates the gui.
|
|
|
|
*
|
|
|
|
* @param parent the parent
|
|
|
|
*/
|
2015-11-15 22:15:37 +01:00
|
|
|
@PostConstruct
|
|
|
|
public void createGui(Composite parent) {
|
|
|
|
comboViewer = new ComboViewer(parent, SWT.NONE);
|
|
|
|
Combo comboBox = comboViewer.getCombo();
|
|
|
|
comboBox.setBounds(0, 0, 26, 22);
|
2017-01-23 22:53:14 +01:00
|
|
|
comboBox.setText(Messages.RelationTypeToolControl_1);
|
2015-11-15 22:15:37 +01:00
|
|
|
comboViewer.setContentProvider(new ArrayContentProvider());
|
|
|
|
comboViewer.setInput(new RelationType[] {dummy});
|
|
|
|
comboViewer.setSelection(new StructuredSelection(dummy));
|
|
|
|
comboViewer.addSelectionChangedListener(this);
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see com.minres.scviewer.e4.application.parts.PartListener#partActivated(org.eclipse.e4.ui.model.application.ui.basic.MPart)
|
|
|
|
*/
|
2015-11-15 22:15:37 +01:00
|
|
|
@Override
|
|
|
|
public void partActivated(MPart part) {
|
2015-11-22 12:47:07 +01:00
|
|
|
if(part.getObject() instanceof WaveformViewer){
|
|
|
|
waveformViewerPart=(WaveformViewer) part.getObject();
|
2015-11-15 22:15:37 +01:00
|
|
|
checkSelection(waveformViewerPart.getSelection());
|
|
|
|
} else {
|
|
|
|
waveformViewerPart=null;
|
|
|
|
checkSelection(new StructuredSelection());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Sets the selection.
|
|
|
|
*
|
|
|
|
* @param selection the selection
|
|
|
|
* @param partService the part service
|
|
|
|
*/
|
2015-11-15 22:15:37 +01:00
|
|
|
@Inject
|
|
|
|
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){
|
|
|
|
MPart part = partService.getActivePart();
|
2015-11-22 12:47:07 +01:00
|
|
|
if(part!=null && part.getObject() instanceof WaveformViewer && comboViewer!=null){
|
2015-11-15 22:15:37 +01:00
|
|
|
checkSelection(selection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/**
|
|
|
|
* Check selection.
|
|
|
|
*
|
|
|
|
* @param selection the selection
|
|
|
|
*/
|
2015-11-15 22:15:37 +01:00
|
|
|
protected void checkSelection(ISelection selection) {
|
|
|
|
if( selection instanceof IStructuredSelection) {
|
|
|
|
Object object= ((IStructuredSelection)selection).getFirstElement();
|
|
|
|
if(object instanceof ITx && waveformViewerPart!=null){
|
|
|
|
comboViewer.getCombo().setEnabled(true);
|
|
|
|
comboViewer.setInput(waveformViewerPart.getSelectionRelationTypes());//getAllRelationTypes());
|
|
|
|
comboViewer.setSelection(new StructuredSelection(waveformViewerPart.getRelationTypeFilter()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
comboViewer.getCombo().setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2015-11-22 12:47:07 +01:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
|
|
|
|
*/
|
2015-11-15 22:15:37 +01:00
|
|
|
@Override
|
|
|
|
public void selectionChanged(SelectionChangedEvent event) {
|
|
|
|
MPart part = partService.getActivePart();
|
2015-11-22 12:47:07 +01:00
|
|
|
if(part!=null && part.getObject() instanceof WaveformViewer && !event.getSelection().isEmpty()){
|
|
|
|
WaveformViewer waveformViewerPart=(WaveformViewer) part.getObject();
|
2015-11-15 22:15:37 +01:00
|
|
|
if(event.getSelection() instanceof IStructuredSelection){
|
|
|
|
waveformViewerPart.setNavigationRelationType(
|
|
|
|
(RelationType)((IStructuredSelection)event.getSelection()).getFirstElement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|