Package de.innovationgate.eclipse.editors.preferences

Source Code of de.innovationgate.eclipse.editors.preferences.ProjectHeaderPreferencePage

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/

package de.innovationgate.eclipse.editors.preferences;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.helpers.HeaderHandler;
import de.innovationgate.eclipse.utils.ui.WidgetFactory;

public class ProjectHeaderPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {

    private Map<String, HeaderHandler> _headerFileMap;
    private Map<String, Text> _headerTabTextMap = new HashMap<String, Text>();

    public ProjectHeaderPreferencePage() {
        setDescription("This page defines a default headers which will be added to new TML an TMLScript-Modules.");
        _headerFileMap = Plugin.getDefault().getHeaderFileMap();
    }

    @Override
    protected Control createContents(Composite parent) {
        Composite container = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout();
        layout.numColumns = 1;
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        layout.horizontalSpacing = 0;
        layout.verticalSpacing = 0;
        container.setLayout(layout);
       
       
        TabFolder headerTabFolder = new TabFolder (container, SWT.NONE);
        headerTabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
        for (String current : _headerFileMap.keySet()) {
            String titel = _headerFileMap.get(current).getTitle();
            TabItem tabItem = new TabItem (headerTabFolder, SWT.FILL);
            Composite tabItemContainer = new Composite(headerTabFolder, SWT.NONE);
            layout = new GridLayout();
            layout.numColumns = 1;
            layout.marginWidth = 0;
            layout.marginHeight = 0;
            layout.horizontalSpacing = 0;
            layout.verticalSpacing = 0;
            tabItemContainer.setLayout(layout);                      
            tabItem.setText (titel);
           
            Text headerTabText = new Text(tabItemContainer, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
            headerTabText.setData(current);
            headerTabText.setText(_headerFileMap.get(current).getDefaultHeader());      
           
            headerTabText.addModifyListener(new ModifyListener() {               
                public void modifyText(ModifyEvent e) {
                    if(e.getSource() instanceof Text){
                        Text source = (Text)e.getSource();
                        _headerFileMap.get((String)source.getData()).setDefaultHeader(source.getText());
                    }                 
                }
            });
           
            GridData codeLayout = new GridData(GridData.FILL_BOTH);
            codeLayout.minimumHeight = WidgetFactory.computeFontHeight(headerTabText) * 20;
            headerTabText.setLayoutData(codeLayout);
            _headerTabTextMap.put(current, headerTabText);
            tabItem.setControl (tabItemContainer);
        }     

        return container;
    }

    @Override
    protected void performDefaults() {
        for (String current : _headerFileMap.keySet()) {
            _headerFileMap.get(current).setDefaultHeader("");
            _headerTabTextMap.get(current).setText(_headerFileMap.get(current).getDefaultHeader());
        }       
    }

    @Override
    public boolean performOk() {
        writeChanges();
        return super.performOk();
    }

    @Override
    protected void performApply() {       
        writeChanges();
        super.performApply();
    }

    private void writeChanges() {
        for (String current : _headerFileMap.keySet()) {
            _headerFileMap.get(current).writeDefaultHeaderFile();
        }
    }

    public void init(IWorkbench workbench) {

    }

}
TOP

Related Classes of de.innovationgate.eclipse.editors.preferences.ProjectHeaderPreferencePage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.