csalter | a3a2daa | 2005-06-15 06:53:51 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2002 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Common Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/cpl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM - Initial API and implementation |
| 10 | * Jens Lukowski/Innoopract - initial renaming/restructuring |
| 11 | * |
| 12 | */ |
| 13 | package org.eclipse.wst.xml.ui.internal.catalog; |
| 14 | |
| 15 | |
| 16 | import org.eclipse.swt.SWT; |
| 17 | import org.eclipse.swt.graphics.Color; |
| 18 | import org.eclipse.swt.layout.GridData; |
| 19 | import org.eclipse.swt.widgets.Composite; |
| 20 | import org.eclipse.swt.widgets.ScrollBar; |
| 21 | import org.eclipse.swt.widgets.Text; |
| 22 | import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; |
| 23 | import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | public class XMLCatalogEntryDetailsView |
| 29 | { |
| 30 | public static final String copyright = "(c) Copyright IBM Corporation 2002."; |
| 31 | protected Text detailsText; |
| 32 | protected ScrollBar verticalScroll, horizontalScroll; |
| 33 | |
| 34 | public XMLCatalogEntryDetailsView(Composite parent) |
| 35 | { |
| 36 | Color color = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); |
| 37 | |
| 38 | detailsText = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); |
| 39 | |
| 40 | GridData data = new GridData(GridData.FILL_BOTH); |
| 41 | data.heightHint = 65; |
| 42 | detailsText.setLayoutData(data); |
| 43 | |
| 44 | verticalScroll = detailsText.getVerticalBar(); |
| 45 | verticalScroll.setVisible(false); |
| 46 | horizontalScroll = detailsText.getHorizontalBar(); |
| 47 | detailsText.setEditable(false); |
| 48 | detailsText.setBackground(color); |
| 49 | } |
| 50 | |
| 51 | public void setCatalogElement(ICatalogEntry entry) |
| 52 | { |
| 53 | String value = getDisplayValue(entry != null ? entry.getURI() : ""); |
| 54 | String line1 = XMLCatalogMessages.UI_LABEL_DETAILS_URI_COLON + "\t\t" + value; |
| 55 | |
| 56 | value = entry != null ? getKeyTypeValue(entry) : ""; |
| 57 | String line2 = XMLCatalogMessages.UI_KEY_TYPE_DETAILS_COLON + "\t" + value; |
| 58 | |
| 59 | value = getDisplayValue(entry != null ? entry.getKey() : ""); |
| 60 | String line3 = XMLCatalogMessages.UI_LABEL_DETAILS_KEY_COLON + "\t\t" + value; |
| 61 | |
| 62 | String entireString = "\n" + line1 + "\n" + line2 + "\n" + line3; |
| 63 | detailsText.setText(entireString); |
| 64 | } |
| 65 | |
| 66 | public void setCatalogElement(INextCatalog nextCatalog) |
| 67 | { |
| 68 | String value = getDisplayValue(nextCatalog != null ? nextCatalog.getCatalogLocation() : ""); |
| 69 | String line1 = XMLCatalogMessages.UI_LABEL_DETAILS_URI_COLON + "\t\t" + value; |
| 70 | |
| 71 | String entireString = "\n" + line1; |
| 72 | detailsText.setText(entireString); |
| 73 | } |
| 74 | |
| 75 | protected String getDisplayValue(String string) |
| 76 | { |
| 77 | return string != null ? string : ""; |
| 78 | } |
| 79 | |
| 80 | protected String getKeyTypeValue(ICatalogEntry entry) |
| 81 | { |
| 82 | String result = null; |
| 83 | if (entry.getURI() != null && entry.getURI().endsWith("xsd")) |
| 84 | { |
| 85 | result = (entry.getEntryType() == ICatalogEntry.ENTRY_TYPE_URI) ? |
| 86 | XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_XSD_PUBLIC : |
| 87 | XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_XSD_SYSTEM; |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | switch (entry.getEntryType()) { |
| 92 | case ICatalogEntry.ENTRY_TYPE_PUBLIC: |
| 93 | result = XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_PUBLIC; |
| 94 | break; |
| 95 | case ICatalogEntry.ENTRY_TYPE_SYSTEM: |
| 96 | result = XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_DTD_SYSTEM; |
| 97 | break; |
| 98 | default: |
| 99 | result = XMLCatalogMessages.UI_KEY_TYPE_DESCRIPTION_URI; |
| 100 | break; |
| 101 | } |
| 102 | |
| 103 | } |
| 104 | return result; |
| 105 | } |
| 106 | } |