at.spardat.xma.guidesign.presentation.dialog.table.TransformTableLayoutDialog.java Source code

Java tutorial

Introduction

Here is the source code for at.spardat.xma.guidesign.presentation.dialog.table.TransformTableLayoutDialog.java

Source

/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat 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:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

/*
 * @(#)
 *
 *
 *
 *
 *
 */
package at.spardat.xma.guidesign.presentation.dialog.table;

import java.util.Iterator;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

import at.spardat.xma.guidesign.GuidesignPackage;
import at.spardat.xma.guidesign.XMATable;
import at.spardat.xma.guidesign.XMATableColumn;
import at.spardat.xma.guidesign.presentation.GuidesignEditor;
import at.spardat.xma.guidesign.presentation.dialog.IValidCompositeListener;
import at.spardat.xma.guidesign.presentation.dialog.XMADialog;
import at.spardat.xma.guidesign.provider.XMATableColumnItemProvider;
import at.spardat.xma.mdl.table.TableLayoutManager;
import at.spardat.xma.page.Scaler;

/**
 *
 *
 * @author S1462
 * @since guidesign.editor
 */
public class TransformTableLayoutDialog extends XMADialog {

    /**
     * hold the New Widget Coposite
     */
    protected TransformTableLayoutComposite tlComposite;
    // remeber the table which has to be recalculated
    private XMATable table;

    /**
     * @param shell
     * @param _lblProvider
     * @param _object
     * @param _feature
     * @param _name
     * @param _editor
     */
    public TransformTableLayoutDialog(Shell shell, XMATable table, EReference _feature, String _name,
            GuidesignEditor _editor) {
        super(shell, table, _feature, _name, _editor);
        this.table = table;

    }

    /* (non-Javadoc)
     * @see at.spardat.xma.guidesign.presentation.XMADialog#isDialogComplete()
     */
    protected boolean isDialogComplete() {
        if (tlComposite.isCompositeComplete()) {
            setMessage(getText("_UI_TransformTableLayoutDialog_description"));
            //setDefaultImage(...);
            return true;
        }
        return false;
    }

    /**
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
    protected void configureShell(Shell shell) {
        super.configureShell(shell, 0, 0);
        shell.setText(getText("_UI_TransformTableLayoutDialog_title"));
        shell.setImage(lblProvider.getImage(object));
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
    protected Control createDialogArea(Composite parent) {
        super.createDialogArea(parent);
        tlComposite = new TransformTableLayoutComposite();
        tlComposite.createComposite(content);
        initControls();
        tlComposite.addListener((IValidCompositeListener) this);
        return content;
    }

    private void initControls() {
        setTitle(getText("_UI_TransformTableLayoutDialog_title"));
        setMessage(getText("_UI_TransformTableLayoutDialog_description"));
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
    protected void okPressed() {
        final Scaler scaler = Scaler.getInstance(content);
        GuidesignPackage desingPackage = GuidesignPackage.eINSTANCE;
        TransformerTLModel model = new TransformerTLModel();
        tlComposite.getControlValues(model);
        TableLayoutManager mgr = table.getLayoutManager();
        mgr.recalcLayoutInfoFromTable(model.getCalculationParam());
        mgr.layout(true);
        //editor.suspendPreViewRefresh();
        Iterator iter = table.getColumn().iterator();
        CompoundCommand compCmd = new CompoundCommand();
        XMATableColumnItemProvider prov = new XMATableColumnItemProvider(adapterFactory);
        Command cmd = null;
        for (int i = 0; iter.hasNext();) {
            XMATableColumn xmaTC = (XMATableColumn) iter.next();
            if (!xmaTC.isYnHiden()) {
                cmd = prov.createSetCommand(editingDomain, xmaTC, desingPackage.getXMATableColumn_QntPercent(),
                        new Float(mgr.getPercent(i)));
                compCmd.append(cmd);
                cmd = prov.createSetCommand(editingDomain, xmaTC, desingPackage.getXMATableColumn_QntWidth(),
                        new Integer(scaler.convertXToStandard(mgr.getAbsolutWidth(i))));
                compCmd.append(cmd);
                if (model.isCalcMinWidths()) {
                    cmd = prov.createSetCommand(editingDomain, xmaTC, desingPackage.getXMATableColumn_QntMinWidth(),
                            new Integer(scaler.convertXToStandard(mgr.getMinWidth(i))));
                    compCmd.append(cmd);
                }
                if (model.isCalcMaxWidths()) {
                    cmd = prov.createSetCommand(editingDomain, xmaTC, desingPackage.getXMATableColumn_QntMaxWidth(),
                            new Integer(scaler.convertXToStandard(mgr.getMaxWidth(i))));
                    compCmd.append(cmd);
                }
                i++;
            }
        }
        editingDomain.getCommandStack().execute(compCmd);
        super.okPressed();
    }

    /**
     * @return the result of the dialog
     */
    public XMATable getResult() {
        return table;
    }

    /**
     * Create a button bar with only a ok button
     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
     */
    protected void createButtonsForButtonBar(Composite parent) {
        // create OK button
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
    }
}