<commit_before>/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.editor.diagram;

import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.MouseWheelHandler;
import org.eclipse.gef.MouseWheelZoomHandler;
import org.eclipse.gef.SnapToGeometry;
import org.eclipse.gef.SnapToGrid;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.dnd.TemplateTransferDragSourceListener;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.internal.InternalGEFPlugin;
import org.eclipse.gef.palette.PaletteListener;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.tools.AbstractTool;
import org.eclipse.gef.tools.CreationTool;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.AlignmentAction;
import org.eclipse.gef.ui.actions.DirectEditAction;
import org.eclipse.gef.ui.actions.MatchHeightAction;
import org.eclipse.gef.ui.actions.MatchWidthAction;
import org.eclipse.gef.ui.actions.UpdateAction;
import org.eclipse.gef.ui.actions.ZoomInAction;
import org.eclipse.gef.ui.actions.ZoomOutAction;
import org.eclipse.gef.ui.palette.FlyoutPaletteComposite;
import org.eclipse.gef.ui.palette.PaletteViewer;
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
import org.eclipse.gef.ui.palette.PaletteViewerProvider;
import org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette;
import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler;
import org.eclipse.help.IContextProvider;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
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.custom.CLabel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.archimatetool.editor.ArchiPlugin;
import com.archimatetool.editor.diagram.actions.BorderColorAction;
import com.archimatetool.editor.diagram.actions.BringForwardAction;
import com.archimatetool.editor.diagram.actions.BringToFrontAction;
import com.archimatetool.editor.diagram.actions.ConnectionLineWidthAction;
import com.archimatetool.editor.diagram.actions.ConnectionRouterAction;
import com.archimatetool.editor.diagram.actions.CopyAction;
import com.archimatetool.editor.diagram.actions.CutAction;
import com.archimatetool.editor.diagram.actions.DefaultEditPartSizeAction;
import com.archimatetool.editor.diagram.actions.ExportAsImageAction;
import com.archimatetool.editor.diagram.actions.ExportAsImageToClipboardAction;
import com.archimatetool.editor.diagram.actions.FillColorAction;
import com.archimatetool.editor.diagram.actions.FontAction;
import com.archimatetool.editor.diagram.actions.FontColorAction;
import com.archimatetool.editor.diagram.actions.FullScreenAction;
import com.archimatetool.editor.diagram.actions.LineColorAction;
import com.archimatetool.editor.diagram.actions.LockObjectAction;
import com.archimatetool.editor.diagram.actions.PasteAction;
import com.archimatetool.editor.diagram.actions.PasteSpecialAction;
import com.archimatetool.editor.diagram.actions.PrintDiagramAction;
import com.archimatetool.editor.diagram.actions.PropertiesAction;
import com.archimatetool.editor.diagram.actions.ResetAspectRatioAction;
import com.archimatetool.editor.diagram.actions.SelectAllAction;
import com.archimatetool.editor.diagram.actions.SelectElementInTreeAction;
import com.archimatetool.editor.diagram.actions.SendBackwardAction;
import com.archimatetool.editor.diagram.actions.SendToBackAction;
import com.archimatetool.editor.diagram.actions.TextAlignmentAction;
import com.archimatetool.editor.diagram.actions.TextPositionAction;
import com.archimatetool.editor.diagram.actions.ToggleGridEnabledAction;
import com.archimatetool.editor.diagram.actions.ToggleGridVisibleAction;
import com.archimatetool.editor.diagram.actions.ToggleSnapToAlignmentGuidesAction;
import com.archimatetool.editor.diagram.actions.ZoomNormalAction;
import com.archimatetool.editor.diagram.dnd.PaletteTemplateTransferDropTargetListener;
import com.archimatetool.editor.diagram.tools.FormatPainterInfo;
import com.archimatetool.editor.diagram.tools.FormatPainterToolEntry;
import com.archimatetool.editor.diagram.tools.MouseWheelHorizontalScrollHandler;
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.preferences.Preferences;
import com.archimatetool.editor.ui.ArchiLabelProvider;
import com.archimatetool.editor.ui.services.ComponentSelectionManager;
import com.archimatetool.editor.utils.PlatformUtils;
import com.archimatetool.model.IArchimateModel;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModel;



/**
 * Abstract GEF Diagram Editor that checks for valid Editor Input.
 * If the Editor Input is of type NullDiagramEditorInput it shows a warning message.
 * This can happen when Eclipse tries to restore an Editor Part and the Diagram Model cannot be restored
 * because the model's file may have been deleted, renamed or moved on the file system.
 * 
 * @author <NAME>
 */
@SuppressWarnings("restriction")
public abstract class AbstractDiagramEditor extends GraphicalEditorWithFlyoutPalette
implements IDiagramModelEditor, IContextProvider, ITabbedPropertySheetPageContributor {

    /*
     * Error handlers
     */
    private Composite fErrorComposite;
    private NullDiagramEditorInput fNullInput;
    
    /**
     * Graphics Model
     */
    protected IDiagramModel fDiagramModel;
    
    /**
     * Actions that need to be updated after CommandStack changed
     */
    protected List<UpdateAction> fUpdateCommandStackActions = new ArrayList<UpdateAction>();
    
    /**
     * Listen to User Preferences Changes
     */
    protected IPropertyChangeListener appPreferencesListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            applicationPreferencesChanged(event);
        }
    };
    
    /**
     * Application Preference changed
     * @param event
     */
    protected void applicationPreferencesChanged(PropertyChangeEvent event) {
        if(IPreferenceConstants.GRID_SIZE == event.getProperty()) {
            applyUserGridPreferences();
        }
        else if(IPreferenceConstants.GRID_VISIBLE == event.getProperty()) {
            applyUserGridPreferences();
        }
        else if(IPreferenceConstants.GRID_SNAP == event.getProperty()) {
            applyUserGridPreferences();
        }
        else if(IPreferenceConstants.GRID_SHOW_GUIDELINES == event.getProperty()) {
            applyUserGridPreferences();
        }
    }
    
    /**
     * Adapter class to respond to Archimate Model notifications.
     */
    protected Adapter eCoreAdapter = new EContentAdapter() {
        @Override
        public void notifyChanged(Notification msg) {
            super.notifyChanged(msg);
            eCoreModelChanged(msg);
        }
    };
    
    @Override
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
        if(input instanceof NullDiagramEditorInput) {
            fNullInput = (NullDiagramEditorInput)input;
            super.setSite(site);
            super.setInput(input); // Make sure to call super.setInput(input)
            setPartName(input.getName());
        }
        else {
            super.init(site, input);
        }
    }
    
    @Override
    public void setInput(IEditorInput input) {
        super.setInput(input);
        
        // This first - set model
        fDiagramModel = ((DiagramEditorInput)input).getDiagramModel();
        
        // Listen to its notifications
        fDiagramModel.getArchimateModel().eAdapters().add(eCoreAdapter);
        
        // Edit Domain before init
        // Use CommandStack from Model
        DefaultEditDomain domain = new DefaultEditDomain(this) {
            private CommandStack stack;
            
            @Override
            public CommandStack getCommandStack() {
                if(stack == null) {
                    stack = (CommandStack)fDiagramModel.getAdapter(CommandStack.class);
                }
                return stack;
            }
        };
        
        setEditDomain(domain);
        
        // Part Name
        setPartName(input.getName());

        // Listen to App Prefs changes
        Preferences.STORE.addPropertyChangeListener(appPreferencesListener);
    }

    @Override
    public void createPartControl(Composite parent) {
        // Show error message
        if(fNullInput != null) {
            createErrorComposite(parent);
        }
        else {
            super.createPartControl(parent);
            doCreatePartControl(parent);
        }
    }
    
    /**
     * Create the Error composite messate
     * @param parent
     */
    protected void createErrorComposite(Composite parent) {
        fErrorComposite = new Composite(parent, SWT.NULL);
        fErrorComposite.setLayout(new GridLayout());
        fErrorComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        String message1 = Messages.AbstractDiagramEditor_0;
        String message2 = Messages.AbstractDiagramEditor_1;
        CLabel imageLabel = new CLabel(fErrorComposite, SWT.NULL);
        imageLabel.setImage(Display.getDefault().getSystemImage(SWT.ICON_INFORMATION));
        imageLabel.setText(message1);
        String fileName = fNullInput.getFileName();
        if(fileName != null) {
            message2 += " " + fileName; //$NON-NLS-1$
        }
        Label l = new Label(fErrorComposite, SWT.NULL);
        l.setText(message2);
    }
    
    public IDiagramModel getModel() {
        return fDiagramModel;
    }
    
    /**
     * Do the createPartControl(Composite parent) method
     */
    protected abstract void doCreatePartControl(Composite parent);
    
    /**
     * Register a context menu
     */
    protected abstract void registerContextMenu(GraphicalViewer viewer);
    
    /**
     * Create the Root Edit Part
     */
    protected abstract void createRootEditPart(GraphicalViewer viewer);
    
    
    @Override
    protected void configureGraphicalViewer() {
        super.configureGraphicalViewer();

        GraphicalViewer viewer = getGraphicalViewer();
        
        // Key handler
        viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer));
        
        // Context menu
        registerContextMenu(viewer);
        
        // Set the Root Edit Part *before* Actions as the Edit Part will create and register a new ZoomManager
        createRootEditPart(viewer);
        
        // Create Actions after Viewer created and after Root Edit Part set
        createActions(viewer);
        
        // Create a drop target listener for this palette viewer
        // this will enable model element creation by dragging a CombinatedTemplateCreationEntries 
        // from the palette into the editor
        viewer.addDropTargetListener(new PaletteTemplateTransferDropTargetListener(this));
        
        // Set some Properties
        setProperties();
        
        // Update status bar on selection
        hookStatusLineSelectionListener();
    }
    
    // Update status bar on selection<commit_msg>Fix graphical artefacts in diagram when DnD occurs<commit_after>/**
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */
package com.archimatetool.editor.diagram;

import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.GraphicsSource;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalViewer;
import org.eclipse.gef.MouseWheelHandler;
import org.eclipse.gef.MouseWheelZoomHandler;
import org.eclipse.gef.SnapToGeometry;
import org.eclipse.gef.SnapToGrid;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.dnd.TemplateTransferDragSourceListener;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.internal.InternalGEFPlugin;
import org.eclipse.gef.palette.PaletteListener;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.tools.AbstractTool;
import org.eclipse.gef.tools.CreationTool;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.AlignmentAction;
import org.eclipse.gef.ui.actions.DirectEditAction;
import org.eclipse.gef.ui.actions.MatchHeightAction;
import org.eclipse.gef.ui.actions.MatchWidthAction;
import org.eclipse.gef.ui.actions.UpdateAction;
import org.eclipse.gef.ui.actions.ZoomInAction;
import org.eclipse.gef.ui.actions.ZoomOutAction;
import org.eclipse.gef.ui.palette.FlyoutPaletteComposite;
import org.eclipse.gef.ui.palette.PaletteViewer;
import org.eclipse.gef.ui.palette.PaletteViewerPreferences;
import org.eclipse.gef.ui.palette.PaletteViewerProvider;
import org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette;
import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
import org.eclipse.help.IContextProvider;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.commands.ActionHandler;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
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.custom.CLabel;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import com.archimatetool.editor.ArchiPlugin;
import com.archimatetool.editor.diagram.actions.BorderColorAction;
import com.archimatetool.editor.diagram.actions.BringForwardAction;
import com.archimatetool.editor.diagram.actions.BringToFrontAction;
import com.archimatetool.editor.diagram.actions.ConnectionLineWidthAction;
import com.archimatetool.editor.diagram.actions.ConnectionRouterAction;
import com.archimatetool.editor.diagram.actions.CopyAction;
import com.archimatetool.editor.diagram.actions.CutAction;
import com.archimatetool.editor.diagram.actions.DefaultEditPartSizeAction;
import com.archimatetool.editor.diagram.actions.ExportAsImageAction;
import com.archimatetool.editor.diagram.actions.ExportAsImageToClipboardAction;
import com.archimatetool.editor.diagram.actions.FillColorAction;
import com.archimatetool.editor.diagram.actions.FontAction;
import com.archimatetool.editor.diagram.actions.FontColorAction;
import com.archimatetool.editor.diagram.actions.FullScreenAction;
import com.archimatetool.editor.diagram.actions.LineColorAction;
import com.archimatetool.editor.diagram.actions.LockObjectAction;
import com.archimatetool.editor.diagram.actions.PasteAction;
import com.archimatetool.editor.diagram.actions.PasteSpecialAction;
import com.archimatetool.editor.diagram.actions.PrintDiagramAction;
import com.archimatetool.editor.diagram.actions.PropertiesAction;
import com.archimatetool.editor.diagram.actions.ResetAspectRatioAction;
import com.archimatetool.editor.diagram.actions.SelectAllAction;
import com.archimatetool.editor.diagram.actions.SelectElementInTreeAction;
import com.archimatetool.editor.diagram.actions.SendBackwardAction;
import com.archimatetool.editor.diagram.actions.SendToBackAction;
import com.archimatetool.editor.diagram.actions.TextAlignmentAction;
import com.archimatetool.editor.diagram.actions.TextPositionAction;
import com.archimatetool.editor.diagram.actions.ToggleGridEnabledAction;
import com.archimatetool.editor.diagram.actions.ToggleGridVisibleAction;
import com.archimatetool.editor.diagram.actions.ToggleSnapToAlignmentGuidesAction;
import com.archimatetool.editor.diagram.actions.ZoomNormalAction;
import com.archimatetool.editor.diagram.dnd.PaletteTemplateTransferDropTargetListener;
import com.archimatetool.editor.diagram.tools.FormatPainterInfo;
import com.archimatetool.editor.diagram.tools.FormatPainterToolEntry;
import com.archimatetool.editor.diagram.tools.MouseWheelHorizontalScrollHandler;
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.preferences.Preferences;
import com.archimatetool.editor.ui.ArchiLabelProvider;
import com.archimatetool.editor.ui.services.ComponentSelectionManager;
import com.archimatetool.editor.utils.PlatformUtils;
import com.archimatetool.model.IArchimateModel;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IDiagramModel;



/**
 * Abstract GEF Diagram Editor that checks for valid Editor Input.
 * If the Editor Input is of type NullDiagramEditorInput it shows a warning message.
 * This can happen when Eclipse tries to restore an Editor Part and the Diagram Model cannot be restored
 * because the model's file may have been deleted, renamed or moved on the file system.
 * 
 * @author <NAME>
 */
@SuppressWarnings("restriction")
public abstract class AbstractDiagramEditor extends GraphicalEditorWithFlyoutPalette
implements IDiagramModelEditor, IContextProvider, ITabbedPropertySheetPageContributor {

    /*
     * Error handlers
     */
    private Composite fErrorComposite;
    private NullDiagramEditorInput fNullInput;
    
    /**
     * Graphics Model
     */
    protected IDiagramModel fDiagramModel;
    
    /**
     * Actions that need to be updated after CommandStack changed
     */
    protected List<UpdateAction> fUpdateCommandStackActions = new ArrayList<UpdateAction>();
    
    /**
     * Listen to User Preferences Changes
     */
    protected IPropertyChangeListener appPreferencesListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            applicationPreferencesChanged(event);
        }
    };
    
    /**
     * Application Preference changed
     * @param event
     */
    protected void applicationPreferencesChanged(PropertyChangeEvent event) {
        if(IPreferenceConstants.GRID_SIZE == event.getProperty()) {
            applyUserGridPreferences();
        }
        else if(IPreferenceConstants.GRID_VISIBLE == event.getProperty()) {
            applyUserGridPreferences();
        }
        else if(IPreferenceConstants.GRID_SNAP == event.getProperty()) {
            applyUserGridPreferences();
        }
        else if(IPreferenceConstants.GRID_SHOW_GUIDELINES == event.getProperty()) {
            applyUserGridPreferences();
        }
    }
    
    /**
     * Adapter class to respond to Archimate Model notifications.
     */
    protected Adapter eCoreAdapter = new EContentAdapter() {
        @Override
        public void notifyChanged(Notification msg) {
            super.notifyChanged(msg);
            eCoreModelChanged(msg);
        }
    };
    
    @Override
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
        if(input instanceof NullDiagramEditorInput) {
            fNullInput = (NullDiagramEditorInput)input;
            super.setSite(site);
            super.setInput(input); // Make sure to call super.setInput(input)
            setPartName(input.getName());
        }
        else {
            super.init(site, input);
        }
    }
    
    @Override
    public void setInput(IEditorInput input) {
        super.setInput(input);
        
        // This first - set model
        fDiagramModel = ((DiagramEditorInput)input).getDiagramModel();
        
        // Listen to its notifications
        fDiagramModel.getArchimateModel().eAdapters().add(eCoreAdapter);
        
        // Edit Domain before init
        // Use CommandStack from Model
        DefaultEditDomain domain = new DefaultEditDomain(this) {
            private CommandStack stack;
            
            @Override
            public CommandStack getCommandStack() {
                if(stack == null) {
                    stack = (CommandStack)fDiagramModel.getAdapter(CommandStack.class);
                }
                return stack;
            }
        };
        
        setEditDomain(domain);
        
        // Part Name
        setPartName(input.getName());

        // Listen to App Prefs changes
        Preferences.STORE.addPropertyChangeListener(appPreferencesListener);
    }

    @Override
    public void createPartControl(Composite parent) {
        // Show error message
        if(fNullInput != null) {
            createErrorComposite(parent);
        }
        else {
            super.createPartControl(parent);
            doCreatePartControl(parent);
        }
    }
    
    /**
     * Create the Error composite messate
     * @param parent
     */
    protected void createErrorComposite(Composite parent) {
        fErrorComposite = new Composite(parent, SWT.NULL);
        fErrorComposite.setLayout(new GridLayout());
        fErrorComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        String message1 = Messages.AbstractDiagramEditor_0;
        String message2 = Messages.AbstractDiagramEditor_1;
        CLabel imageLabel = new CLabel(fErrorComposite, SWT.NULL);
        imageLabel.setImage(Display.getDefault().getSystemImage(SWT.ICON_INFORMATION));
        imageLabel.setText(message1);
        String fileName = fNullInput.getFileName();
        if(fileName != null) {
            message2 += " " + fileName; //$NON-NLS-1$
        }
        Label l = new Label(fErrorComposite, SWT.NULL);
        l.setText(message2);
    }
    
    public IDiagramModel getModel() {
        return fDiagramModel;
    }
    
    /**
     * Do the createPartControl(Composite parent) method
     */
    protected abstract void doCreatePartControl(Composite parent);
    
    /**
     * Register a context menu
     */
    protected abstract void registerContextMenu(GraphicalViewer viewer);
    
    /**
     * Create the Root Edit Part
     */
    protected abstract void createRootEditPart(GraphicalViewer viewer);
    
    
    @Override
    protected void configureGraphicalViewer() {
        super.configureGraphicalViewer();

        GraphicalViewer viewer = getGraphicalViewer();
        
        // Key handler
        viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer));
        
        // Context menu
        registerContextMenu(viewer);
        
        // Set the Root Edit Part *before* Actions as the Edit Part will create and register a new ZoomManager
        createRootEditPart(viewer);
        
        // Create Actions after Viewer created and after Root Edit Part set
        createActions(viewer);
        
        // Create a drop target listener for this palette viewer
        // this will enable model element creation by dragging a CombinatedTemplateCreationEntries 
        // from the palette into the editor
        viewer.addDropTargetListener(new PaletteTemplateTransferDropTargetListener(this));
        
        // Set some Properties
        setProperties();
        
        // Update status bar on selection
        hookStatusLineSelectionListener();
    }
    
    @Override
    protected void createGraphicalViewer(Composite parent) {
        // Hack: specialize the GraphicsSource to avoid calling the
        // Canvas#update() method in the GraphicsSource#getGraphics(Rectangle) method.
        // This hack is needed to avoid SWT/GEF bug 137786
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=137786) where drag over
        // feedback (ie the drag feedback provided by the drag source) and drag under
        // feedback (ie the feedback provided by the drop target) interfere with each
        // other, causing flickering and more importantly ugly graphical artifacts.
        //
        // In order to be able to specialize the GraphicsSource, we need to specialize
        // the LightWeightSystem, and to do that we need in turn to specialize the GraphicalViewer.
        final GraphicalViewer viewer = new ScrollingGraphicalViewer() {
            @Override
            protected LightweightSystem createLightweightSystem() {
                return new LightweightSystem() {
                    @Override
                    public void setControl(final Canvas c) {
                        super.setControl(c);
                        this.getUpdateManager().setGraphicsSource(new GraphicsSource() {
                            @Override
                            public Graphics getGraphics(Rectangle r) {
                                c.redraw(r.x, r.y, r.width, r.height, false);
                                // The actual hack is the following code
                                // line: in original GEF code a call is
                                // made to the #update() method of the c Canvas.
                                // But calling #update() at this point
                                // causes SWT to redraw the drag over
                                // feedback which in turn causes GEF to
                                // redraw the drag under feedback etc.
                                // The final result is flickering
                                // (because of constant erase and
                                // redraw) and graphical artifacts.
                                // Commenting this line however seems to
                                // have no side effect (so far).
                                // c.update();
                                return null;
                            }
        
                            @Override
                            public void flushGraphics(Rectangle region) {
                                // Nothing to do.
                            }
                        });
                    }
                };
            }
        };

        viewer.createControl(parent);
        setGraphicalViewer(viewer);
        configureGraphicalViewer();
        hookGraphicalViewer();
        initializeGraphicalViewer();
    }

    // Update status bar on selection
{'fraction_non_alphanumeric': 0.08392135370281564, 'fraction_numerical': 0.0013016373227375487, 'mean_word_length': 3.217102412249025, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2658176', 'n_tokens_mistral': 8066, 'n_tokens_neox': 8028, 'n_words': 1577}