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 | *******************************************************************************/ |
david_williams | f3680f0 | 2005-04-13 22:43:54 +0000 | [diff] [blame] | 13 | package org.eclipse.wst.xml.ui.internal.dialogs; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 14 | |
| 15 | import org.eclipse.core.resources.IFile; |
| 16 | import org.eclipse.core.runtime.IPath; |
| 17 | import org.eclipse.jface.window.Window; |
| 18 | import org.eclipse.swt.widgets.Shell; |
| 19 | import org.eclipse.swt.widgets.Text; |
csalter | 4d4e387 | 2005-06-06 18:58:08 +0000 | [diff] [blame] | 20 | import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; |
csalter | a3a2daa | 2005-06-15 06:53:51 +0000 | [diff] [blame] | 21 | import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; |
david_williams | 5f2420f | 2005-04-12 12:23:57 +0000 | [diff] [blame] | 22 | import org.eclipse.wst.xml.ui.internal.XMLUIMessages; |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 23 | |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 24 | public 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_williams | 5f2420f | 2005-04-12 12:23:57 +0000 | [diff] [blame] | 34 | dialog.getShell().setText(XMLUIMessages._UI_LABEL_SELECT_XML_CATALOG_ENTRY); //$NON-NLS-1$ |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 35 | 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$ |
csalter | 2d43e97 | 2005-05-25 17:56:39 +0000 | [diff] [blame] | 50 | SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(parentShell, extensions, ICatalogEntry.ENTRY_TYPE_SYSTEM); |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 51 | dialog.create(); |
david_williams | 5f2420f | 2005-04-12 12:23:57 +0000 | [diff] [blame] | 52 | dialog.getShell().setText(XMLUIMessages._UI_LABEL_SPECIFY_SYSTEM_ID); //$NON-NLS-1$ |
david_williams | 9621348 | 2004-11-11 09:07:12 +0000 | [diff] [blame] | 53 | 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 | } |