<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.ui.components;

import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;

import com.archimatetool.editor.ui.UIUtils;

/**
 * Tree Text CellEditor
 * 
 * @author <NAME>
 */
public class TreeTextCellEditor extends TextCellEditor {
    int minHeight = 0;
    CellEditorGlobalActionHandler fGlobalActionHandler;

    public TreeTextCellEditor(Tree tree) {
        super(tree, SWT.BORDER);
        Text txt = (Text)getControl();
        
        // Filter out nasties
        UIUtils.applyInvalidCharacterFilter(txt);
        
        // Not sure if we need this
        //UIUtils.conformSingleTextControl(txt);

        FontData[] fontData = txt.getFont().getFontData();
        if(fontData != null && fontData.length > 0) {
            minHeight = fontData[0].getHeight() + 10;
        }
    }

    @Override
    public LayoutData getLayoutData() {
        LayoutData data = super.getLayoutData();
        if(minHeight > 0) {
            data.minimumHeight = minHeight;
        }
        return data;
    }
    
    @Override
    public void activate() {
        // Clear global key binds
        fGlobalActionHandler = new CellEditorGlobalActionHandler();
        fGlobalActionHandler.clearGlobalActions();
    }
    
    @Override
    public void deactivate() {
        super.deactivate();
        
        // Restore global key binds
        if(fGlobalActionHandler != null) {
            fGlobalActionHandler.restoreGlobalActions();
            fGlobalActionHandler = null;
        }
    }
}<commit_msg>Fix Tree Text Editor not clearing global key bindings when new Diagram is created<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.ui.components;

import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;

import com.archimatetool.editor.ui.UIUtils;

/**
 * Tree Text CellEditor
 * 
 * @author <NAME>
 */
public class TreeTextCellEditor extends TextCellEditor {
    int minHeight = 0;
    CellEditorGlobalActionHandler fGlobalActionHandler;

    public TreeTextCellEditor(Tree tree) {
        super(tree, SWT.BORDER);
        Text txt = (Text)getControl();
        
        // Filter out nasties
        UIUtils.applyInvalidCharacterFilter(txt);
        
        // Not sure if we need this
        //UIUtils.conformSingleTextControl(txt);

        FontData[] fontData = txt.getFont().getFontData();
        if(fontData != null && fontData.length > 0) {
            minHeight = fontData[0].getHeight() + 10;
        }
    }

    @Override
    public LayoutData getLayoutData() {
        LayoutData data = super.getLayoutData();
        if(minHeight > 0) {
            data.minimumHeight = minHeight;
        }
        return data;
    }
    
    @Override
    protected void doSetFocus() {
        super.doSetFocus();
        
        // Clear global key binds
        // We do this on doSetFocus() rather than activate() because in the case where we open an EditorPart on new diagram
        // the focus gets transferred to the EditorPart and we end up with the wrong actionBars
        fGlobalActionHandler = new CellEditorGlobalActionHandler();
        fGlobalActionHandler.clearGlobalActions();
    }
    
    @Override
    public void deactivate() {
        super.deactivate();
        
        // Restore global key binds
        if(fGlobalActionHandler != null) {
            fGlobalActionHandler.restoreGlobalActions();
            fGlobalActionHandler = null;
        }
    }
}
{'fraction_non_alphanumeric': 0.08987654320987655, 'fraction_numerical': 0.002962962962962963, 'mean_word_length': 2.528745644599303, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6126912', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1096, 'n_words': 291}