Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c7d0101ef4857de2732a87d363a3f91775a5a210 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*******************************************************************************
 * Copyright (c) 2010, 2013 Wind River Systems, Inc. and others.
 * 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:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.debug.ui.launch;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.tcf.internal.debug.ui.ImageCache;
import org.eclipse.tcf.internal.debug.ui.model.TCFModel;
import org.eclipse.tcf.services.IPathMap;

class PathMapRuleDialog extends TitleAreaDialog {

    private final IPathMap.PathMapRule pathMapRule;
    private final boolean enable_editing;
    private final boolean showContextQuery;
    private final Image image;

    private Text source_text;
    private Text destination_text;
    private Text context_query_text;
    private Button destination_button;

    PathMapRuleDialog(Shell parent, Image image, IPathMap.PathMapRule pathMapRule, boolean enable_editing, boolean showContextQuery) {
        super(parent);
        this.image = image != null ? image : ImageCache.getImage(ImageCache.IMG_PATH);
        this.pathMapRule = pathMapRule;
        this.enable_editing = enable_editing;
        this.showContextQuery = showContextQuery;
        setHelpAvailable(false);
    }
    
    @Override
    protected void configureShell(Shell shell) {
        super.configureShell(shell);
        shell.setText("File Path Map Rule"); //$NON-NLS-1$
        shell.setImage(image);
    }

    @Override
    protected void createButtonsForButtonBar(Composite parent) {
        createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
        createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
        updateButtons();
    }

    @Override
    protected Control createDialogArea(Composite parent) {
        setTitle("Add or edit source and destination path mapping rule"); //$NON-NLS-1$
        setMessage("Source and destination are absolute path fragments.\nThe rule is applied if the source path fragment matches or is a prefix of a path to map."); //$NON-NLS-1$
        
        Composite composite = (Composite)super.createDialogArea(parent);
        createFileNameFields(composite);
        setData();
        composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
        //PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(), "org.eclipse.tcf.debug.ui.add_path_map_rule"); //$NON-NLS-1$
        return composite;
    }

    private void createFileNameFields(Composite parent) {
        Font font = parent.getFont();
        Composite composite = new Composite(parent, SWT.NONE);
        GridLayout layout = new GridLayout(3, false);
        composite.setFont(font);
        composite.setLayout(layout);
        composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        Label source_label = new Label(composite, SWT.NONE);
        source_label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        source_label.setFont(font);
        source_label.setText("Source:"); //$NON-NLS-1$

        source_text = new Text(composite, SWT.SINGLE | SWT.BORDER);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.widthHint = 300;
        gd.horizontalSpan = 2;
        source_text.setLayoutData(gd);
        source_text.setFont(font);
        source_text.setEditable(enable_editing);

        source_text.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                updateButtons();
            }
        });

        Label destination_label = new Label(composite, SWT.NONE);
        destination_label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        destination_label.setFont(font);
        destination_label.setText("Destination:"); //$NON-NLS-1$

        destination_text = new Text(composite, SWT.SINGLE | SWT.BORDER);
        destination_text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        destination_text.setFont(font);
        destination_text.setEditable(enable_editing);

        destination_text.addModifyListener(new ModifyListener() {
            public void modifyText(ModifyEvent e) {
                updateButtons();
            }
        });

        destination_button = new Button(composite, SWT.PUSH);
        destination_button.setText("Browse..."); //$NON-NLS-1$
        destination_button.setFont(font);
        destination_button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        destination_button.setEnabled(enable_editing);
        destination_button.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.NONE);
                dialog.setFilterPath(destination_text.getText());
                String path = dialog.open();
                if (path != null) destination_text.setText(path);
            }
        });

        if (showContextQuery) {
            Label context_query_label = new Label(composite, SWT.NONE);
            context_query_label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
            context_query_label.setFont(font);
            context_query_label.setText("Context Query:"); //$NON-NLS-1$

            context_query_text = new Text(composite, SWT.SINGLE | SWT.BORDER);
            gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.widthHint = 200;
            gd.horizontalSpan = 2;
            context_query_text.setLayoutData(gd);
            context_query_text.setFont(font);
            context_query_text.setEditable(enable_editing);

            context_query_text.addModifyListener(new ModifyListener() {
                public void modifyText(ModifyEvent e) {
                    updateButtons();
                }
            });
        }
    }

    private void setData() {
        source_text.setText(pathMapRule.getSource() != null ? pathMapRule.getSource() : ""); //$NON-NLS-1$
        destination_text.setText(pathMapRule.getDestination() != null ? pathMapRule.getDestination() : ""); //$NON-NLS-1$
        if (context_query_text != null)
            context_query_text.setText(pathMapRule.getContextQuery() != null ? pathMapRule.getContextQuery() : ""); //$NON-NLS-1$
        updateButtons();
    }

    private void getData() {
        if (source_text.getText().trim().length() > 0)
            pathMapRule.getProperties().put(IPathMap.PROP_SOURCE, source_text.getText());
        else
            pathMapRule.getProperties().remove(IPathMap.PROP_SOURCE);

        if (destination_text.getText().trim().length() > 0)
            pathMapRule.getProperties().put(IPathMap.PROP_DESTINATION, destination_text.getText());
        else
            pathMapRule.getProperties().remove(IPathMap.PROP_DESTINATION);

        if (context_query_text != null && context_query_text.getText().trim().length() > 0)
            pathMapRule.getProperties().put(IPathMap.PROP_CONTEXT_QUERY, context_query_text.getText());
        else
            pathMapRule.getProperties().remove(IPathMap.PROP_CONTEXT_QUERY);
    }

    private void updateButtons() {
        Button btn = getButton(IDialogConstants.OK_ID);
        if (btn != null && source_text != null) btn.setEnabled(!enable_editing || source_text.getText().trim().length() > 0);
    }

    @Override
    protected void okPressed() {
        if (enable_editing) {
            try {
                getData();
            }
            catch (Throwable x) {
                MessageBox mb = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.OK);
                mb.setText("Invalid data"); //$NON-NLS-1$
                mb.setMessage(TCFModel.getErrorMessage(x, true));
                mb.open();
                return;
            }
        }
        super.okPressed();
    }
}

Back to the top