blob: 4fbec4563d053df2807db613cd415c6eb8de84cd [file] [log] [blame]
david_williams96213482004-11-11 09:07:12 +00001/*******************************************************************************
2 * Copyright (c) 2001, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
david_williamsf3680f02005-04-13 22:43:54 +000013package org.eclipse.wst.xml.ui.internal.dialogs;
david_williams96213482004-11-11 09:07:12 +000014
15import org.eclipse.core.resources.IFile;
16import org.eclipse.core.runtime.IPath;
17import org.eclipse.jface.window.Window;
18import org.eclipse.swt.widgets.Shell;
19import org.eclipse.swt.widgets.Text;
csalter4d4e3872005-06-06 18:58:08 +000020import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
csaltera3a2daa2005-06-15 06:53:51 +000021import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry;
david_williams5f2420f2005-04-12 12:23:57 +000022import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
david_williams96213482004-11-11 09:07:12 +000023
david_williams96213482004-11-11 09:07:12 +000024public class EditEntityHelper {
25
26 public void performBrowseForPublicId(Shell parentShell, Text publicIdField) {
27 performBrowseForPublicId(parentShell, publicIdField, null);
28 }
29
30 public void performBrowseForPublicId(Shell parentShell, Text publicIdField, Text systemIdField) {
31 String[] extensions = {"dtd", "txt"}; //$NON-NLS-1$ //$NON-NLS-2$
32 SelectXMLCatalogIdDialog dialog = new SelectXMLCatalogIdDialog(parentShell, extensions);
33 dialog.create();
david_williams5f2420f2005-04-12 12:23:57 +000034 dialog.getShell().setText(XMLUIMessages._UI_LABEL_SELECT_XML_CATALOG_ENTRY); //$NON-NLS-1$
david_williams96213482004-11-11 09:07:12 +000035 dialog.setBlockOnOpen(true);
36 dialog.open();
37 if (dialog.getReturnCode() == Window.OK) {
38 String id = dialog.getId();
39 if (id != null) {
40 publicIdField.setText(id);
41 if (systemIdField != null && dialog.getSystemId() != null) {
42 systemIdField.setText(dialog.getSystemId());
43 }
44 }
45 }
46 }
47
48 public void performBrowseForSystemId(Shell parentShell, Text systemIdField, IPath resourceLocation) {
49 String[] extensions = {"dtd"}; //$NON-NLS-1$
csalter2d43e972005-05-25 17:56:39 +000050 SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(parentShell, extensions, ICatalogEntry.ENTRY_TYPE_SYSTEM);
david_williams96213482004-11-11 09:07:12 +000051 dialog.create();
david_williams5f2420f2005-04-12 12:23:57 +000052 dialog.getShell().setText(XMLUIMessages._UI_LABEL_SPECIFY_SYSTEM_ID); //$NON-NLS-1$
david_williams96213482004-11-11 09:07:12 +000053 dialog.setBlockOnOpen(true);
54 dialog.open();
55 if (dialog.getReturnCode() == Window.OK) {
56 String id = dialog.getId();
57 IFile file = dialog.getFile();
58 if (id != null) {
59 systemIdField.setText(id);
60 } else if (file != null) {
61 String uri = null;
62 if (resourceLocation != null) {
63 uri = URIHelper.getRelativeURI(file.getLocation(), resourceLocation);
64 } else {
65 uri = file.getLocation().toOSString();
66 }
67 systemIdField.setText(uri);
68 }
69 }
70 }
71}