Package de.innovationgate.eclipse.editors.models

Source Code of de.innovationgate.eclipse.editors.models.MultiLineTextCellEditor

/*******************************************************************************
* 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.models;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.StatusDialog;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class MultiLineTextCellEditor extends DialogCellEditor {
   
    public static class MultiLineTextDialog extends StatusDialog {       
        private Text _text;
        private String _initialValue;
        private String _value;
       
       
        protected MultiLineTextDialog(Shell parentShell) {
            super(parentShell);
        }
       
        public String getText() {
            return _value;
        }

        @Override
        protected Control createDialogArea(Composite parent) {
            Composite composite = new Composite(parent, SWT.NONE);
            GridData data = new GridData(GridData.FILL, GridData.FILL, true, true);
            data.minimumWidth = 500;
            data.minimumHeight = 200;
            composite.setLayoutData(data);
            composite.setLayout(new FillLayout());
            _text = new Text(composite, SWT.MULTI|SWT.V_SCROLL);
            _text.setText(_initialValue);
            return composite;
        }

        public int open(String value) {
            _initialValue = value;
            return super.open();
        }

        @Override
        protected void okPressed() {
            _value = _text.getText();
            super.okPressed();
        }
    }

   
   
    public MultiLineTextCellEditor(Composite parent) {
        super(parent);
    }



    @Override
    protected Object openDialogBox(Control cellEditorWindow) {
        MultiLineTextDialog dialog = new MultiLineTextDialog(cellEditorWindow.getShell());
        dialog.setTitle("Edit text value");
       
        int result = -1;
        if (getValue() != null) {
            result = dialog.open(getValue().toString());   
        } else {
            result = dialog.open("");
        }
               
        if (result == Dialog.OK) {
            return dialog.getText();
        } else {
            return null;
        }
    }

}
TOP

Related Classes of de.innovationgate.eclipse.editors.models.MultiLineTextCellEditor

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.