david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame^] | 1 | /******************************************************************************* |
| 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 | *******************************************************************************/ |
| 13 | |
| 14 | |
| 15 | package org.eclipse.wst.xml.ui.dialogs; |
| 16 | |
| 17 | import org.eclipse.core.resources.IFile; |
| 18 | import org.eclipse.core.runtime.IPath; |
| 19 | import org.eclipse.jface.window.Window; |
| 20 | import org.eclipse.swt.widgets.Shell; |
| 21 | import org.eclipse.swt.widgets.Text; |
| 22 | import org.eclipse.wst.xml.ui.util.XMLCommonResources; |
| 23 | import org.eclipse.wst.xml.uriresolver.XMLCatalogEntry; |
| 24 | import org.eclipse.wst.xml.uriresolver.util.URIHelper; |
| 25 | |
| 26 | |
| 27 | |
| 28 | public class EditEntityHelper { |
| 29 | |
| 30 | public void performBrowseForPublicId(Shell parentShell, Text publicIdField) { |
| 31 | performBrowseForPublicId(parentShell, publicIdField, null); |
| 32 | } |
| 33 | |
| 34 | public void performBrowseForPublicId(Shell parentShell, Text publicIdField, Text systemIdField) { |
| 35 | String[] extensions = {"dtd", "txt"}; //$NON-NLS-1$ //$NON-NLS-2$ |
| 36 | SelectXMLCatalogIdDialog dialog = new SelectXMLCatalogIdDialog(parentShell, extensions); |
| 37 | dialog.create(); |
| 38 | dialog.getShell().setText(XMLCommonResources.getInstance().getString("_UI_LABEL_SELECT_XML_CATALOG_ENTRY")); //$NON-NLS-1$ |
| 39 | dialog.setBlockOnOpen(true); |
| 40 | dialog.open(); |
| 41 | if (dialog.getReturnCode() == Window.OK) { |
| 42 | String id = dialog.getId(); |
| 43 | if (id != null) { |
| 44 | publicIdField.setText(id); |
| 45 | if (systemIdField != null && dialog.getSystemId() != null) { |
| 46 | systemIdField.setText(dialog.getSystemId()); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public void performBrowseForSystemId(Shell parentShell, Text systemIdField, IPath resourceLocation) { |
| 53 | String[] extensions = {"dtd"}; //$NON-NLS-1$ |
| 54 | SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(parentShell, extensions, XMLCatalogEntry.SYSTEM); |
| 55 | dialog.create(); |
| 56 | dialog.getShell().setText(XMLCommonResources.getInstance().getString("_UI_LABEL_SPECIFY_SYSTEM_ID")); //$NON-NLS-1$ |
| 57 | dialog.setBlockOnOpen(true); |
| 58 | dialog.open(); |
| 59 | if (dialog.getReturnCode() == Window.OK) { |
| 60 | String id = dialog.getId(); |
| 61 | IFile file = dialog.getFile(); |
| 62 | if (id != null) { |
| 63 | systemIdField.setText(id); |
| 64 | } else if (file != null) { |
| 65 | String uri = null; |
| 66 | if (resourceLocation != null) { |
| 67 | uri = URIHelper.getRelativeURI(file.getLocation(), resourceLocation); |
| 68 | } else { |
| 69 | uri = file.getLocation().toOSString(); |
| 70 | } |
| 71 | systemIdField.setText(uri); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |