Search in sources :

Example 1 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project dbeaver by serge-rider.

the class ProjectExportWizard method saveResourceProperties.

private void saveResourceProperties(IResource resource, XMLBuilder xml) throws CoreException, IOException {
    if (resource instanceof IFile) {
        final IContentDescription contentDescription = ((IFile) resource).getContentDescription();
        if (contentDescription != null && contentDescription.getCharset() != null) {
            xml.addAttribute(ExportConstants.ATTR_CHARSET, contentDescription.getCharset());
        //xml.addAttribute(ExportConstants.ATTR_CHARSET, contentDescription.getContentType());
        }
    } else if (resource instanceof IFolder) {
        xml.addAttribute(ExportConstants.ATTR_DIRECTORY, true);
    }
    for (Object entry : resource.getPersistentProperties().entrySet()) {
        Map.Entry<?, ?> propEntry = (Map.Entry<?, ?>) entry;
        xml.startElement(ExportConstants.TAG_ATTRIBUTE);
        final QualifiedName attrName = (QualifiedName) propEntry.getKey();
        xml.addAttribute(ExportConstants.ATTR_QUALIFIER, attrName.getQualifier());
        xml.addAttribute(ExportConstants.ATTR_NAME, attrName.getLocalName());
        xml.addAttribute(ExportConstants.ATTR_VALUE, (String) propEntry.getValue());
        xml.endElement();
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) QualifiedName(org.eclipse.core.runtime.QualifiedName) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project dbeaver by serge-rider.

the class ProjectImportWizard method loadResourceProperties.

private void loadResourceProperties(DBRProgressMonitor monitor, IResource resource, Element element) throws CoreException, IOException {
    if (resource instanceof IFile) {
        final String charset = element.getAttribute(ExportConstants.ATTR_CHARSET);
        if (!CommonUtils.isEmpty(charset)) {
            ((IFile) resource).setCharset(charset, RuntimeUtils.getNestedMonitor(monitor));
        }
    }
    for (Element attrElement : XMLUtils.getChildElementList(element, ExportConstants.TAG_ATTRIBUTE)) {
        String qualifier = attrElement.getAttribute(ExportConstants.ATTR_QUALIFIER);
        String name = attrElement.getAttribute(ExportConstants.ATTR_NAME);
        String value = attrElement.getAttribute(ExportConstants.ATTR_VALUE);
        if (!CommonUtils.isEmpty(qualifier) && !CommonUtils.isEmpty(name) && !CommonUtils.isEmpty(value)) {
            resource.setPersistentProperty(new QualifiedName(qualifier, name), value);
        }
    }
}
Also used : Element(org.w3c.dom.Element) QualifiedName(org.eclipse.core.runtime.QualifiedName)

Example 3 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project ow by vtst.

the class LessProjectPropertyPage method createContents.

@Override
protected Control createContents(Composite parent) {
    Composite composite = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH);
    Label label = SWTFactory.createLabel(composite, messages.getString("LessProjectPropertyPage_includePaths"), 1);
    label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    includePaths.createContents(IContainer.class, composite);
    label = SWTFactory.createLabel(composite, messages.getString("LessProjectPropertyPage_roots"), 1);
    label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    roots.createContents(IFile.class, composite);
    final IContentType lessContentType = Platform.getContentTypeManager().getContentType(LessRuntimeModule.CONTENT_TYPE_ID);
    final IProject project = this.getProject();
    roots.setAddFilter(new ViewerFilter() {

        public boolean select(Viewer viewer, Object parent, Object element) {
            if (element instanceof IProject)
                return project.equals(element);
            else if (element instanceof IContainer)
                return true;
            else if (element instanceof IFile) {
                IFile file = (IFile) element;
                try {
                    if (file.getContentDescription() == null)
                        return false;
                    IContentType fileContentType = file.getContentDescription().getContentType();
                    if (fileContentType != null && fileContentType.isKindOf(lessContentType))
                        return true;
                } catch (CoreException e) {
                }
            }
            return false;
        }
    });
    try {
        includePaths.setCurrentValue(ResourceListProperty.<IContainer>get(IContainer.class, getProject(), new QualifiedName(LessProjectProperty.QUALIFIER, LessProjectProperty.INCLUDE_PATHS)));
        roots.setCurrentValue(ResourceListProperty.<IFile>get(IFile.class, getProject(), new QualifiedName(LessProjectProperty.QUALIFIER, LessProjectProperty.ROOTS)));
    } catch (CoreException e) {
        this.setErrorMessage(e.getMessage());
    }
    return composite;
}
Also used : IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) IContentType(org.eclipse.core.runtime.content.IContentType) Viewer(org.eclipse.jface.viewers.Viewer) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject)

Example 4 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project ow by vtst.

the class LessProjectPropertyPage method performOk.

@Override
public boolean performOk() {
    try {
        ResourceListProperty.<IContainer>set(getProject(), new QualifiedName(LessProjectProperty.QUALIFIER, LessProjectProperty.INCLUDE_PATHS), includePaths.getCurrentValue());
        ResourceListProperty.<IFile>set(getProject(), new QualifiedName(LessProjectProperty.QUALIFIER, LessProjectProperty.ROOTS), roots.getCurrentValue());
    } catch (CoreException e) {
        this.setErrorMessage(e.getMessage());
        return false;
    }
    ;
    return super.performOk();
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) IContainer(org.eclipse.core.resources.IContainer)

Example 5 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project sling by apache.

the class ProjectUtilTest method oldContentSyncRootIsMigrated.

@Test
public void oldContentSyncRootIsMigrated() throws Exception {
    QualifiedName oldPropertyQName = new QualifiedName("org.apache.sling.ide.eclipse-core", "sync_root");
    IPath contentSyncPath = Path.fromPortableString("src/main/content/jcr_root");
    project.ensureDirectoryExists(contentSyncPath);
    // simulate the old property being set
    contentProject.setPersistentProperty(oldPropertyQName, contentSyncPath.toString());
    // query the data through the API, old value should be obeyed
    assertThat("Old sync_root not obeyed", ProjectUtil.getSyncDirectory(contentProject).getProjectRelativePath(), equalTo(contentSyncPath));
    // the old store should no longer have the config value
    assertThat("Old property not removed", contentProject.getPersistentProperty(oldPropertyQName), nullValue());
    // a second query should work just the same, to make sure that after deleting the data from the old store we get the right value back
    assertThat("sync_root not obeyed after old store for property was deleted", ProjectUtil.getSyncDirectory(contentProject).getProjectRelativePath(), equalTo(contentSyncPath));
}
Also used : IPath(org.eclipse.core.runtime.IPath) QualifiedName(org.eclipse.core.runtime.QualifiedName) Test(org.junit.Test)

Aggregations

QualifiedName (org.eclipse.core.runtime.QualifiedName)8 CoreException (org.eclipse.core.runtime.CoreException)4 IFile (org.eclipse.core.resources.IFile)3 Map (java.util.Map)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 HashMap (java.util.HashMap)1 ZipEntry (java.util.zip.ZipEntry)1 IFolder (org.eclipse.core.resources.IFolder)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1