Search in sources :

Example 41 with IContainer

use of org.eclipse.core.resources.IContainer in project AutoRefactor by JnRouvignac.

the class JavaCoreHelper method createFolder.

private static void createFolder(IFolder folder) throws Exception {
    if (!folder.exists()) {
        final IContainer parent = folder.getParent();
        if (parent instanceof IFolder) {
            createFolder((IFolder) parent);
        }
        folder.create(false, true, null);
    }
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 42 with IContainer

use of org.eclipse.core.resources.IContainer 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 43 with IContainer

use of org.eclipse.core.resources.IContainer 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 44 with IContainer

use of org.eclipse.core.resources.IContainer in project dbeaver by serge-rider.

the class ScriptsExportWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    String outDir = DBeaverCore.getGlobalPreferenceStore().getString(PREF_SCRIPTS_EXPORT_OUT_DIR);
    if (CommonUtils.isEmpty(outDir)) {
        outDir = RuntimeUtils.getUserHomeDir().getAbsolutePath();
    }
    Composite placeholder = UIUtils.createPlaceholder(parent, 1);
    placeholder.setLayout(new GridLayout(1, false));
    // Project list
    scriptsNavigator = new DatabaseNavigatorTree(placeholder, DBeaverCore.getInstance().getNavigatorModel().getRoot(), SWT.BORDER | SWT.CHECK);
    GridData gd = new GridData(GridData.FILL_BOTH);
    scriptsNavigator.setLayoutData(gd);
    CheckboxTreeViewer viewer = (CheckboxTreeViewer) scriptsNavigator.getViewer();
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateState();
        }
    });
    scriptsNavigator.getViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof DBNResource && ((DBNResource) element).getResource() instanceof IContainer;
        }
    });
    // Output folder
    Composite generalSettings = UIUtils.createPlaceholder(placeholder, 3);
    generalSettings.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    {
        overwriteCheck = UIUtils.createCheckbox(generalSettings, CoreMessages.dialog_project_export_wizard_page_checkbox_overwrite_files, false);
        gd = new GridData(GridData.BEGINNING);
        gd.horizontalSpan = 3;
        overwriteCheck.setLayoutData(gd);
        UIUtils.createControlLabel(generalSettings, CoreMessages.dialog_project_export_wizard_page_label_directory);
        directoryText = new Text(generalSettings, SWT.BORDER);
        directoryText.setText(outDir);
        directoryText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        directoryText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                updateState();
            }
        });
        Button openFolder = new Button(generalSettings, SWT.PUSH);
        openFolder.setImage(DBeaverIcons.getImage(DBIcon.TREE_FOLDER));
        openFolder.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.NONE);
                dialog.setMessage(CoreMessages.dialog_project_export_wizard_page_dialog_choose_export_dir_message);
                dialog.setText(CoreMessages.dialog_project_export_wizard_page_dialog_choose_export_dir_text);
                String directory = directoryText.getText();
                if (!CommonUtils.isEmpty(directory)) {
                    dialog.setFilterPath(directory);
                }
                directory = dialog.open();
                if (directory != null) {
                    directoryText.setText(directory);
                }
            }
        });
    }
    setControl(placeholder);
    updateState();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DatabaseNavigatorTree(org.jkiss.dbeaver.ui.navigator.database.DatabaseNavigatorTree) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IContainer(org.eclipse.core.resources.IContainer) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 45 with IContainer

use of org.eclipse.core.resources.IContainer in project dbeaver by serge-rider.

the class NavigatorHandlerObjectCreateCopy method pasteResource.

private void pasteResource(DBNResource resourceNode, DBNResource toFolder) {
    final IResource resource = resourceNode.getResource();
    final IResource targetResource = toFolder.getResource();
    assert resource != null;
    assert targetResource != null;
    final IContainer targetFolder = targetResource instanceof IContainer ? (IContainer) targetResource : targetResource.getParent();
    try {
        DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    copyResource(monitor, resource, targetFolder);
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(null, "Copy error", "Error copying resource", e.getTargetException());
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9