<commit_before>package de.ptb.epics.eve.viewer;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import de.ptb.epics.eve.data.measuringstation.AbstractDevice;
import de.ptb.epics.eve.data.measuringstation.IMeasuringStation;

import de.ptb.epics.eve.viewer.Activator;
import de.ptb.epics.eve.viewer.actions.LoadMeasuringStationAction;

/**
 * A simple view implementation, which only displays a label.
 * 
 * @author PTB
 *
 */
public final class MeasuringStationView extends ViewPart {

	public static final String ID = "MeasuringStationView"; // TODO Needs to be whatever is mentioned in plugin.xml

	private IMeasuringStation measuringStation;
	
	private TreeViewer treeViewer;
	
	private DragSource source;
	
	private LoadMeasuringStationAction loadMeasuringStationAction;
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setFocus() {
	
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void createPartControl( final Composite parent ) {
		
		measuringStation = Activator.getDefault().getMeasuringStation();
		if( measuringStation == null ) {
			final Label errorLabel = new Label( parent, SWT.NONE );
			errorLabel.setText( "No device description has been loaded. Please check Preferences!" );
			return;
		}
				
		final FillLayout fillLayout = new FillLayout();
		parent.setLayout( fillLayout );
		this.treeViewer = new TreeViewer( parent );
		this.treeViewer.setContentProvider( new MeasuringStationTreeViewContentProvider() );
		this.treeViewer.setLabelProvider( new MeasuringStationTreeViewLabelProvider() );
		this.treeViewer.getTree().setEnabled( false );
		this.treeViewer.getTree().addMouseListener( new MouseListener() {

			@Override
			public void mouseDoubleClick(MouseEvent e) {
				IViewReference[] ref = getSite().getPage().getViewReferences();
				for( final IViewReference r : ref ) {
					final IViewPart view = r.getView( false );
					if( r.getId().equals( "DeviceInspectorView" ) && getSite().getPage().isPartVisible( view ) ) {
						if( treeViewer.getTree().getSelection()[0].getData() instanceof AbstractDevice ) {
							((DeviceInspectorViewer)view).addAbstractDevice( (AbstractDevice)treeViewer.getTree().getSelection()[0].getData() );
						}
					}
				}
				
			}

			@Override
			public void mouseDown(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		this.treeViewer.addDoubleClickListener( new IDoubleClickListener() {

			@Override
			public void doubleClick(DoubleClickEvent event) {
				IViewReference[] ref = getSite().getPage().getViewReferences();
				for( final IViewReference r : ref ) {
					final IViewPart view = r.getView( false );
					if( r.getId().equals( "DeviceInspectorView" ) && getSite().getPage().isPartVisible( view ) ) {
						if( treeViewer.getTree().getSelection()[0].getData() instanceof AbstractDevice ) {
							((DeviceInspectorViewer)view).addAbstractDevice( (AbstractDevice)treeViewer.getTree().getSelection()[0].getData() );
						}
					}
				}
				
			}
			
		});
		
		this.source = new DragSource( this.treeViewer.getTree(), DND.DROP_COPY | DND.DROP_MOVE );
		Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
		source.setTransfer( types );
		source.addDragListener( new DragSourceListener() {

			public void dragStart( final DragSourceEvent event ) {
				if( treeViewer.getTree().getSelection().length == 0 ) {
					event.doit = false;
				} else {
					event.doit = true;<commit_msg>Yeah, finally found the error. There was an infinitve loop at the hashCode and equals functions.<commit_after>package de.ptb.epics.eve.viewer;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import de.ptb.epics.eve.data.measuringstation.AbstractDevice;
import de.ptb.epics.eve.data.measuringstation.IMeasuringStation;

import de.ptb.epics.eve.viewer.Activator;
import de.ptb.epics.eve.viewer.actions.LoadMeasuringStationAction;

/**
 * A simple view implementation, which only displays a label.
 * 
 * @author PTB
 *
 */
public final class MeasuringStationView extends ViewPart {

	public static final String ID = "MeasuringStationView"; // TODO Needs to be whatever is mentioned in plugin.xml

	private IMeasuringStation measuringStation;
	
	private TreeViewer treeViewer;
	
	private DragSource source;
	
	private LoadMeasuringStationAction loadMeasuringStationAction;
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setFocus() {
	
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void createPartControl( final Composite parent ) {
		
		measuringStation = Activator.getDefault().getMeasuringStation();
		if( measuringStation == null ) {
			final Label errorLabel = new Label( parent, SWT.NONE );
			errorLabel.setText( "No device description has been loaded. Please check Preferences!" );
			return;
		}
				
		final FillLayout fillLayout = new FillLayout();
		parent.setLayout( fillLayout );
		this.treeViewer = new TreeViewer( parent );
		this.treeViewer.setContentProvider( new MeasuringStationTreeViewContentProvider() );
		this.treeViewer.setLabelProvider( new MeasuringStationTreeViewLabelProvider() );
		this.treeViewer.getTree().setEnabled( false );
		/*this.treeViewer.getTree().addMouseListener( new MouseListener() {

			@Override
			public void mouseDoubleClick(MouseEvent e) {
				IViewReference[] ref = getSite().getPage().getViewReferences();
				for( final IViewReference r : ref ) {
					final IViewPart view = r.getView( false );
					if( r.getId().equals( "DeviceInspectorView" ) && getSite().getPage().isPartVisible( view ) ) {
						if( treeViewer.getTree().getSelection()[0].getData() instanceof AbstractDevice ) {
							((DeviceInspectorViewer)view).addAbstractDevice( (AbstractDevice)treeViewer.getTree().getSelection()[0].getData() );
						}
					}
				}
				
			}

			@Override
			public void mouseDown(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});*/
		
		this.treeViewer.addDoubleClickListener( new IDoubleClickListener() {

			@Override
			public void doubleClick(DoubleClickEvent event) {
				IViewReference[] ref = getSite().getPage().getViewReferences();
				for( final IViewReference r : ref ) {
					final IViewPart view = r.getView( false );
					if( r.getId().equals( "DeviceInspectorView" ) && getSite().getPage().isPartVisible( view ) ) {
						if( treeViewer.getTree().getSelection()[0].getData() instanceof AbstractDevice ) {
							((DeviceInspectorViewer)view).addAbstractDevice( (AbstractDevice)treeViewer.getTree().getSelection()[0].getData() );
						}
					}
				}
				
			}
			
		});
		
		this.source = new DragSource( this.treeViewer.getTree(), DND.DROP_COPY | DND.DROP_MOVE );
		Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
		source.setTransfer( types );
		source.addDragListener( new DragSourceListener() {

			public void dragStart( final DragSourceEvent event ) {
				if( treeViewer.getTree().getSelection().length == 0 ) {
					event.doit = false;
				} else {
					event.doit = true;
{'fraction_non_alphanumeric': 0.11787632992731487, 'fraction_numerical': 0.0010534077741493732, 'mean_word_length': 4.303910614525139, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4377570', 'n_tokens_mistral': 3315, 'n_tokens_neox': 2903, 'n_words': 576}