Search in sources :

Example 6 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class XMLCatalogEntriesView method updateWidgetEnabledState.

protected void updateWidgetEnabledState() {
    boolean isEditable = false;
    ISelection selection = tableViewer.getSelection();
    boolean multipleSelection = false;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.size() > 1) {
            multipleSelection = true;
        }
        Object selectedObject = structuredSelection.getFirstElement();
        if (selectedObject instanceof ICatalogElement) {
            ICatalogElement[] elements = ((Catalog) workingUserCatalog).getCatalogElements();
            // dw List entriesList = new ArrayList(elements.length);
            for (int i = 0; i < elements.length; i++) {
                ICatalogElement element = elements[i];
                isEditable = selectedObject.equals(element);
                if (isEditable) {
                    break;
                }
            }
        }
    }
    // if (isPageEnabled)
    {
        editButton.setEnabled(isEditable & !multipleSelection);
        deleteButton.setEnabled(isEditable);
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) ICatalogElement(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog) Point(org.eclipse.swt.graphics.Point)

Example 7 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class CatalogTest method testCatalog.

public void testCatalog() throws Exception {
    Catalog workingUserCatalog = new Catalog(null, "working", null);
    assertNotNull(userCatalog);
    workingUserCatalog.addEntriesFromCatalog(userCatalog);
    ICatalogEntry catalogEntry = (ICatalogEntry) userCatalog.createCatalogElement(ICatalogEntry.ENTRY_TYPE_PUBLIC);
    catalogEntry.setKey("testKey");
    catalogEntry.setURI("http://testuri");
    workingUserCatalog.addCatalogElement(catalogEntry);
    userCatalog.addEntriesFromCatalog(workingUserCatalog);
    String userCatalogLocation = userCatalog.getLocation();
    userCatalog.save();
    userCatalog.clear();
    userCatalog = getCatalog(XMLCorePlugin.USER_CATALOG_ID, userCatalogLocation);
    List entries = getCatalogEntries(userCatalog, ICatalogEntry.ENTRY_TYPE_PUBLIC);
    assertEquals(1, entries.size());
    ICatalogEntry entry = (ICatalogEntry) entries.get(0);
    assertEquals("http://testuri", entry.getURI());
    assertEquals("testKey", entry.getKey());
}
Also used : List(java.util.List) ICatalogEntry(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog)

Example 8 with Catalog

use of org.eclipse.wst.xml.core.internal.catalog.Catalog in project webtools.sourceediting by eclipse.

the class CatalogWriterTest method testReadAndWriteComplexCatalog.

/*
	 * Class under test for void read(ICatalog, String)
	 */
public void testReadAndWriteComplexCatalog() throws Exception {
    // read catalog
    String catalogFile = "/data/delegateAndRewrite/catalog11.xml";
    URL catalogUrl = TestPlugin.getDefault().getBundle().getEntry(catalogFile);
    assertNotNull(catalogUrl);
    URL base = FileLocator.resolve(catalogUrl);
    Catalog catalog = (Catalog) getCatalog("catalog11", base.toString());
    // CatalogReader.read(catalog, catalogFilePath);
    assertNotNull(catalog);
    // test main catalog - catalog1.xml
    // assertEquals("cat1", catalog.getId());
    assertEquals(13, catalog.getCatalogElements().length);
    // write catalog so we can read it back in
    URL resultsFolder = TestPlugin.getDefault().getBundle().getEntry("/");
    IPath path = new Path(FileLocator.resolve(resultsFolder).getFile());
    String resultCatalogFile = path.append("/catalog11-x.xml").toFile().toURI().toString();
    catalog.setLocation(resultCatalogFile);
    // write catalog
    catalog.save();
    // read catalog file from the saved location and test its content
    catalog = (Catalog) getCatalog("catalog2", catalog.getLocation());
    assertNotNull(catalog);
    // test main catalog - catalog1.xml
    // assertEquals("cat1", catalog.getId());
    assertEquals(13, catalog.getCatalogElements().length);
    // test public entries
    assertEquals(2, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_PUBLIC).size());
    // test system entries
    assertEquals(2, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_SYSTEM).size());
    // test uri entries
    assertEquals(1, CatalogTest.getCatalogEntries(catalog, ICatalogEntry.ENTRY_TYPE_URI).size());
    // test next catalog - catalog2.xml
    INextCatalog[] nextCatalogEntries = catalog.getNextCatalogs();
    assertEquals(1, nextCatalogEntries.length);
    INextCatalog nextCatalogEntry = (INextCatalog) nextCatalogEntries[0];
    assertNotNull(nextCatalogEntry);
    assertEquals("catalog.xml", nextCatalogEntry.getCatalogLocation());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) URL(java.net.URL) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) Catalog(org.eclipse.wst.xml.core.internal.catalog.Catalog)

Aggregations

Catalog (org.eclipse.wst.xml.core.internal.catalog.Catalog)8 URL (java.net.URL)6 INextCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog)6 List (java.util.List)4 ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)4 ICatalogEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry)4 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 File (java.io.File)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Point (org.eclipse.swt.graphics.Point)1 ICatalogElement (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement)1