Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 2987b045caf08769b95001252d201b32ec57bf1e (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
/*******************************************************************************
 * Copyright (c) 2001, 2006 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *	   David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences
 *******************************************************************************/
package org.eclipse.wst.xml.ui.internal.dialogs;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.ui.part.PageBook;
import org.eclipse.wst.common.ui.internal.viewers.SelectSingleFileView;
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry;
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;


public class SelectFileOrXMLCatalogIdPanel extends Composite implements SelectionListener {

	/**
	 * TODO: Change the name of this interface; "Listener" is used by SWT.
	 */
	public interface Listener {
		void completionStateChanged();
	}

	protected class MySelectSingleFileView extends SelectSingleFileView implements SelectSingleFileView.Listener {
		protected Control control;

		public MySelectSingleFileView(Composite parent) {
			super(null, true);
			// String[] ext = {".dtd"};
			// addFilterExtensions(ext);
			control = createControl(parent);
			control.setLayoutData(new GridData(GridData.FILL_BOTH));
			MySelectSingleFileView.this.setListener(this);
		}

		public Control getControl() {
			return control;
		}

		public void setControlComplete(boolean isComplete) {
			updateCompletionStateChange();
		}

		public void setVisibleHelper(boolean isVisible) {
			super.setVisibleHelper(isVisible);
		}
	}

	protected Listener listener;
	protected PageBook pageBook;

	protected Button[] radioButton;
	protected MySelectSingleFileView selectSingleFileView;
	protected SelectXMLCatalogIdPanel selectXMLCatalogIdPanel;

	public SelectFileOrXMLCatalogIdPanel(Composite parent) {
		super(parent, SWT.NONE);

		// container group
		setLayout(new GridLayout());
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.heightHint = 400;
		gd.widthHint = 400;
		setLayoutData(gd);

		radioButton = new Button[2];
		radioButton[0] = new Button(this, SWT.RADIO);
		radioButton[0].setText(XMLUIMessages._UI_RADIO_BUTTON_SELECT_FROM_WORKSPACE);
		radioButton[0].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		radioButton[0].setSelection(true);
		radioButton[0].addSelectionListener(this);

		radioButton[1] = new Button(this, SWT.RADIO);
		radioButton[1].setText(XMLUIMessages._UI_RADIO_BUTTON_SELECT_FROM_CATALOG);
		radioButton[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		radioButton[1].addSelectionListener(this);

		pageBook = new PageBook(this, SWT.NONE);
		pageBook.setLayoutData(new GridData(GridData.FILL_BOTH));

		selectSingleFileView = new MySelectSingleFileView(pageBook);

		ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
		selectXMLCatalogIdPanel = new SelectXMLCatalogIdPanel(pageBook, xmlCatalog);
		selectXMLCatalogIdPanel.getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() {
			public void selectionChanged(SelectionChangedEvent event) {
				updateCompletionStateChange();
			}
		});
		Dialog.applyDialogFont(parent);
		pageBook.showPage(selectSingleFileView.getControl());

	}

	public IFile getFile() {
		IFile result = null;
		if (radioButton[0].getSelection()) {
			result = selectSingleFileView.getFile();
		}
		return result;
	}

	public ICatalogEntry getXMLCatalogEntry() {
		ICatalogEntry result = null;
		if (radioButton[1].getSelection()) {
			result = selectXMLCatalogIdPanel.getXMLCatalogEntry();
		}
		return result;
	}

	public String getXMLCatalogId() {
		String result = null;
		if (radioButton[1].getSelection()) {
			result = selectXMLCatalogIdPanel.getId();
		}
		return result;
	}

	public String getXMLCatalogURI() {
		String result = null;
		if (radioButton[1].getSelection()) {
			result = selectXMLCatalogIdPanel.getURI();
		}
		return result;
	}

	public void setCatalogEntryType(int catalogEntryType) {
		selectXMLCatalogIdPanel.setCatalogEntryType(catalogEntryType);
	}

	public void setFilterExtensions(String[] filterExtensions) {
		selectSingleFileView.resetFilters();
		selectSingleFileView.addFilterExtensions(filterExtensions);

		selectXMLCatalogIdPanel.getTableViewer().setFilterExtensions(filterExtensions);
	}

	public void setListener(Listener listener) {
		this.listener = listener;
	}

	public void setVisibleHelper(boolean isVisible) {
		selectSingleFileView.setVisibleHelper(isVisible);
	}

	public void updateCompletionStateChange() {
		if (listener != null) {
			listener.completionStateChanged();
		}
	}

	public void widgetDefaultSelected(SelectionEvent e) {
	}

	public void widgetSelected(SelectionEvent e) {
		if (e.widget == radioButton[0]) {
			pageBook.showPage(selectSingleFileView.getControl());
		}
		else {
			pageBook.showPage(selectXMLCatalogIdPanel);
		}
		updateCompletionStateChange();
	}
}

Back to the top