Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0b89a4abcf16935b4964f46a449ab8a4f19c9a62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2007, 2014 Borland Software Corporation and others.
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 * 
 * Contributors:
 *     Borland Software Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.m2m.internal.qvt.oml.runtime.ui.launch;

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

import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.m2m.internal.qvt.oml.common.MdaException;
import org.eclipse.m2m.internal.qvt.oml.common.launch.IQvtLaunchConstants;
import org.eclipse.m2m.internal.qvt.oml.common.launch.ISetMessageEx;
import org.eclipse.m2m.internal.qvt.oml.common.ui.launch.TransformationControls;
import org.eclipse.m2m.internal.qvt.oml.emf.util.EmfUtil;
import org.eclipse.m2m.internal.qvt.oml.runtime.project.ITransformationMaker;
import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformation;
import org.eclipse.m2m.internal.qvt.oml.runtime.project.config.QvtConfigurationProperty;
import org.eclipse.m2m.internal.qvt.oml.runtime.ui.QvtRuntimeUIPlugin;
import org.eclipse.m2m.internal.qvt.oml.runtime.ui.QvtTransformationConfigurationUI;
import org.eclipse.m2m.internal.qvt.oml.runtime.ui.QvtTransformationConfigurationUI.PropertyChangeListener;
import org.eclipse.m2m.internal.qvt.oml.runtime.ui.wizards.ApplyTransformationData;
import org.eclipse.m2m.internal.qvt.oml.runtime.util.MiscUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

public class QvtTransformationConfigurationTab extends AbstractLaunchConfigurationTab {

    public QvtTransformationConfigurationTab(ITransformationMaker transformationMaker) {
        myTransformationMaker = transformationMaker;
        myData = new ApplyTransformationData();
        myUI = new QvtTransformationConfigurationUI(myData, new ISetMessageEx() {
            public void setErrorMessage(String message) {
                QvtTransformationConfigurationTab.this.setErrorMessage(message);
                QvtTransformationConfigurationTab.this.getLaunchConfigurationDialog().updateMessage();
            }

            public void setMessage(String message) {
                QvtTransformationConfigurationTab.this.setMessage(message);
                QvtTransformationConfigurationTab.this.getLaunchConfigurationDialog().updateMessage();
            }

			public void setWarningMessage(String message) {
				if (!AbstractLaunchConfigurationTabCompatibility.setWarningMessage(QvtTransformationConfigurationTab.this, message)) {
					QvtTransformationConfigurationTab.this.setMessage(message);
				}
			
                QvtTransformationConfigurationTab.this.getLaunchConfigurationDialog().updateMessage();
			}
        });
        myUI.addPropertyChangeListener(new PropertyChangeListener() {
            public void changePerformed(QvtConfigurationProperty property) {
                updateLaunchConfigurationDialog();
            }
        });
    }
    
    public void createControl(Composite parent) {
        Composite composite = new Composite(parent, SWT.NONE);
        composite.setLayout(new GridLayout(TransformationControls.GRID, false));
        
        myUI.createControl(composite);
        
        setControl(composite);
        Dialog.applyDialogFont(composite);
    }

	public void initializeFrom(ILaunchConfiguration configuration) {
        String fileName = ""; //$NON-NLS-1$
        try {
            fileName = configuration.getAttribute(IQvtLaunchConstants.MODULE, ""); //$NON-NLS-1$
        } catch (CoreException e) {
           QvtRuntimeUIPlugin.getDefault().getLog().log(MiscUtil.makeErrorStatus(e));
        }
        
        QvtTransformation qvtTransformation = null;
        try {
        	URI uri = EmfUtil.makeUri(fileName);
        	if (uri != null) {
        		qvtTransformation = myTransformationMaker.makeTransformation(uri);
        	}
		} catch (MdaException e) {
			QvtRuntimeUIPlugin.getDefault().getLog().log(MiscUtil.makeErrorStatus(e));
		}
        myData.setTransformation(qvtTransformation);
        
        Map<String, String> valueMap = Collections.<String, String>emptyMap();
        try {
            valueMap = configuration.getAttribute(IQvtLaunchConstants.CONFIGURATION_PROPERTIES, Collections.<String, String>emptyMap());
        } catch (CoreException e) {
            QvtRuntimeUIPlugin.getDefault().getLog().log(MiscUtil.makeErrorStatus(e));
        }
        myData.getConfiguration().clear();
        myData.getConfiguration().putAll(valueMap);
        
        myUI.loadValues();
    }

    public void performApply(ILaunchConfigurationWorkingCopy configuration) {
        myUI.performApply();
        Map<String, String> map = new HashMap<String, String>(myData.getConfiguration());
        configuration.setAttribute(IQvtLaunchConstants.CONFIGURATION_PROPERTIES, map);
   }

    public String getName() {
        return Messages.QvtTransformationConfigurationTab_Name;
    }
    
    @Override
    public boolean isValid(ILaunchConfiguration launchConfig) {
        myUI.validate();
        return myUI.isValid();
    }
    
    @Override
    public Image getImage() {
        return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEF_VIEW);
    }
    
    public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {

    }

    private final ApplyTransformationData myData;
    private final QvtTransformationConfigurationUI myUI;
    private final ITransformationMaker myTransformationMaker;
}

Back to the top