Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8e61d1dde8ca261988679689b6e10a46d73ab9c0 (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
/*******************************************************************************
 * Copyright (c) 2001, 2004 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
 *     
 *******************************************************************************/


package org.eclipse.wst.xml.ui.dialogs;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.xml.ui.util.XMLCommonResources;
import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry;
import org.eclipse.wst.xml.uriresolver.util.URIHelper;



public class EditEntityHelper {

	public void performBrowseForPublicId(Shell parentShell, Text publicIdField) {
		performBrowseForPublicId(parentShell, publicIdField, null);
	}

	public void performBrowseForPublicId(Shell parentShell, Text publicIdField, Text systemIdField) {
		String[] extensions = {"dtd", "txt"}; //$NON-NLS-1$ //$NON-NLS-2$
		SelectXMLCatalogIdDialog dialog = new SelectXMLCatalogIdDialog(parentShell, extensions);
		dialog.create();
		dialog.getShell().setText(XMLCommonResources.getInstance().getString("_UI_LABEL_SELECT_XML_CATALOG_ENTRY")); //$NON-NLS-1$
		dialog.setBlockOnOpen(true);
		dialog.open();
		if (dialog.getReturnCode() == Window.OK) {
			String id = dialog.getId();
			if (id != null) {
				publicIdField.setText(id);
				if (systemIdField != null && dialog.getSystemId() != null) {
					systemIdField.setText(dialog.getSystemId());
				}
			}
		}
	}

	public void performBrowseForSystemId(Shell parentShell, Text systemIdField, IPath resourceLocation) {
		String[] extensions = {"dtd"}; //$NON-NLS-1$
		SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(parentShell, extensions, XMLCatalogEntry.SYSTEM);
		dialog.create();
		dialog.getShell().setText(XMLCommonResources.getInstance().getString("_UI_LABEL_SPECIFY_SYSTEM_ID")); //$NON-NLS-1$
		dialog.setBlockOnOpen(true);
		dialog.open();
		if (dialog.getReturnCode() == Window.OK) {
			String id = dialog.getId();
			IFile file = dialog.getFile();
			if (id != null) {
				systemIdField.setText(id);
			} else if (file != null) {
				String uri = null;
				if (resourceLocation != null) {
					uri = URIHelper.getRelativeURI(file.getLocation(), resourceLocation);
				} else {
					uri = file.getLocation().toOSString();
				}
				systemIdField.setText(uri);
			}
		}
	}
}

Back to the top