Search in sources :

Example 11 with IStringVariableManager

use of org.eclipse.core.variables.IStringVariableManager in project jbosstools-hibernate by jbosstools.

the class PathHelper method checkDirectory.

/**
 * Checks if directory exists.
 * Handles variables replacement too.
 *
 * @param strpath
 * @param name
 * @param checkFilesystem
 * @return
 */
public static String checkDirectory(String strpath, String name, boolean checkFilesystem) {
    if (strpath.indexOf("${") >= 0) {
        // $NON-NLS-1$
        IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
        try {
            manager.validateStringVariables(strpath);
        } catch (CoreException e) {
            String out = NLS.bind(HibernateConsoleMessages.PathHelper_has_invalid_variable_references, name, e.getMessage());
            return out;
        }
    }
    IPath path = pathOrNull(resolve(strpath));
    if (checkFilesystem && path != null) {
        File file = new File(path.toOSString());
        if (file.exists()) {
            if (file.isDirectory()) {
                return null;
            }
            String out = NLS.bind(HibernateConsoleMessages.PathHelper_not_directory, path);
            return out;
        }
    }
    IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    if (res != null) {
        int resType = res.getType();
        if (resType == IResource.PROJECT || resType == IResource.FOLDER) {
            IProject proj = res.getProject();
            if (!proj.isOpen()) {
                String out = NLS.bind(HibernateConsoleMessages.PathHelper_project_for_is_closed, name, path);
                return out;
            }
        } else {
            String out = NLS.bind(HibernateConsoleMessages.PathHelper_has_to_be_folder_or_project, name, path);
            return out;
        }
    } else {
        String out = NLS.bind(HibernateConsoleMessages.PathHelper_does_not_exist, name, path);
        return out;
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) IStringVariableManager(org.eclipse.core.variables.IStringVariableManager) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 12 with IStringVariableManager

use of org.eclipse.core.variables.IStringVariableManager in project jbosstools-hibernate by jbosstools.

the class PathHelper method checkFile.

/**
 * Checks if file exists.
 * Handles variables replacement too.
 *
 * @param strpath
 * @param name
 * @param checkFilesystem
 * @return
 */
public static String checkFile(String strpath, String name, boolean checkFilesystem) {
    if (strpath.indexOf("${") >= 0) {
        // $NON-NLS-1$
        IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
        try {
            manager.validateStringVariables(strpath);
        } catch (CoreException e) {
            String out = NLS.bind(HibernateConsoleMessages.PathHelper_has_invalid_variable_references, name, e.getMessage());
            return out;
        }
    }
    IPath path = pathOrNull(resolve(strpath));
    if (checkFilesystem && path != null) {
        File file = new File(path.toOSString());
        if (file.exists()) {
            if (file.isFile()) {
                return null;
            }
            String out = NLS.bind(HibernateConsoleMessages.PathHelper_not_file, path);
            return out;
        }
    }
    IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    if (res != null) {
        int resType = res.getType();
        if (resType == IResource.FILE) {
            IProject proj = res.getProject();
            if (!proj.isOpen()) {
                String out = NLS.bind(HibernateConsoleMessages.PathHelper_project_for_is_closed, name, path);
                return out;
            }
        } else {
            String out = NLS.bind(HibernateConsoleMessages.PathHelper_has_to_be_file, name, path);
            return out;
        }
    } else {
        String out = NLS.bind(HibernateConsoleMessages.PathHelper_does_not_exist, name, path);
        return out;
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) IStringVariableManager(org.eclipse.core.variables.IStringVariableManager) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 13 with IStringVariableManager

use of org.eclipse.core.variables.IStringVariableManager in project egit by eclipse.

the class RepositoryUtil method getDefaultRepositoryDir.

/**
 * @return The default repository directory as configured in the
 *         preferences, with variables substituted. Returns workspace
 *         location if there was an error during substitution.
 */
@NonNull
public static String getDefaultRepositoryDir() {
    String key = GitCorePreferences.core_defaultRepositoryDir;
    String dir = migrateRepoRootPreference();
    IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
    if (dir == null) {
        dir = Platform.getPreferencesService().getString(Activator.getPluginId(), key, getDefaultDefaultRepositoryDir(), null);
    } else {
        p.put(key, dir);
    }
    IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
    String result;
    try {
        result = manager.performStringSubstitution(dir);
    } catch (CoreException e) {
        // $NON-NLS-1$
        result = "";
    }
    if (result == null || result.isEmpty()) {
        result = ResourcesPlugin.getWorkspace().getRoot().getRawLocation().toOSString();
    }
    return result;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IStringVariableManager(org.eclipse.core.variables.IStringVariableManager) NonNull(org.eclipse.jgit.annotations.NonNull)

Example 14 with IStringVariableManager

use of org.eclipse.core.variables.IStringVariableManager in project egit by eclipse.

the class GitPreferenceRoot method createFieldEditors.

@Override
protected void createFieldEditors() {
    Composite main = getFieldEditorParent();
    GridLayoutFactory.swtDefaults().margins(0, 0).applyTo(main);
    Group cloningGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    cloningGroup.setText(UIText.GitPreferenceRoot_CloningRepoGroupHeader);
    GridDataFactory.fillDefaults().grab(true, false).span(GROUP_SPAN, 1).applyTo(cloningGroup);
    DirectoryFieldEditor editor = new DirectoryFieldEditor(GitCorePreferences.core_defaultRepositoryDir, UIText.GitPreferenceRoot_DefaultRepoFolderLabel, cloningGroup) {

        /**
         * The own control is the variableButton
         */
        private static final int NUMBER_OF_OWN_CONTROLS = 1;

        @Override
        public IPreferenceStore getPreferenceStore() {
            return getSecondaryPreferenceStore();
        }

        @Override
        protected boolean doCheckState() {
            String fileName = getTextControl().getText();
            fileName = fileName.trim();
            if (fileName.length() == 0 && isEmptyStringAllowed())
                return true;
            IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
            String substitutedFileName;
            try {
                substitutedFileName = manager.performStringSubstitution(fileName);
            } catch (CoreException e) {
                // It's apparently invalid
                return false;
            }
            File file = new File(substitutedFileName);
            // require the file to exist
            return !file.exists() || file.isDirectory();
        }

        @Override
        public int getNumberOfControls() {
            return super.getNumberOfControls() + NUMBER_OF_OWN_CONTROLS;
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns - NUMBER_OF_OWN_CONTROLS);
        }

        @Override
        protected void adjustForNumColumns(int numColumns) {
            super.adjustForNumColumns(numColumns - NUMBER_OF_OWN_CONTROLS);
        }

        @Override
        protected void createControl(Composite parent) {
            // setting validate strategy using the setter method is too late
            super.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE);
            super.createControl(parent);
            if (HAS_DEBUG_UI)
                addVariablesButton(parent);
        }

        private void addVariablesButton(Composite parent) {
            Button variableButton = new Button(parent, SWT.PUSH);
            variableButton.setText(UIText.GitPreferenceRoot_DefaultRepoFolderVariableButton);
            variableButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    org.eclipse.debug.ui.StringVariableSelectionDialog dialog = new org.eclipse.debug.ui.StringVariableSelectionDialog(getShell());
                    int returnCode = dialog.open();
                    if (returnCode == Window.OK)
                        setStringValue(dialog.getVariableExpression());
                }
            });
        }
    };
    updateMargins(cloningGroup);
    editor.setEmptyStringAllowed(false);
    editor.getLabelControl(cloningGroup).setToolTipText(UIText.GitPreferenceRoot_DefaultRepoFolderTooltip);
    addField(editor);
    Group remoteConnectionsGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    GridDataFactory.fillDefaults().grab(true, false).span(GROUP_SPAN, 1).applyTo(remoteConnectionsGroup);
    remoteConnectionsGroup.setText(UIText.GitPreferenceRoot_RemoteConnectionsGroupHeader);
    IntegerFieldEditor timeoutEditor = new IntegerFieldEditor(UIPreferences.REMOTE_CONNECTION_TIMEOUT, UIText.RemoteConnectionPreferencePage_TimeoutLabel, remoteConnectionsGroup);
    timeoutEditor.getLabelControl(remoteConnectionsGroup).setToolTipText(UIText.RemoteConnectionPreferencePage_ZeroValueTooltip);
    addField(timeoutEditor);
    updateMargins(remoteConnectionsGroup);
    Group repoChangeScannerGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    GridDataFactory.fillDefaults().grab(true, false).span(GROUP_SPAN, 1).applyTo(repoChangeScannerGroup);
    repoChangeScannerGroup.setText(UIText.GitPreferenceRoot_RepoChangeScannerGroupHeader);
    IntegerFieldEditor intervalField = new IntegerFieldEditor(UIPreferences.REFESH_INDEX_INTERVAL, UIText.RefreshPreferencesPage_RefreshIndexInterval, repoChangeScannerGroup);
    intervalField.getLabelControl(repoChangeScannerGroup).setToolTipText(UIText.RefreshPreferencesPage_RefreshIndexIntervalTooltip);
    addField(intervalField);
    addField(new BooleanFieldEditor(UIPreferences.REFESH_ON_INDEX_CHANGE, UIText.RefreshPreferencesPage_RefreshWhenIndexChange, repoChangeScannerGroup) {

        @Override
        public int getNumberOfControls() {
            return 2;
        }
    });
    addField(new BooleanFieldEditor(UIPreferences.REFESH_ONLY_WHEN_ACTIVE, UIText.RefreshPreferencesPage_RefreshOnlyWhenActive, repoChangeScannerGroup) {

        @Override
        public int getNumberOfControls() {
            return 2;
        }
    });
    updateMargins(repoChangeScannerGroup);
    Group mergeGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    GridDataFactory.fillDefaults().grab(true, false).span(GROUP_SPAN, 1).applyTo(mergeGroup);
    mergeGroup.setText(UIText.GitPreferenceRoot_MergeGroupHeader);
    ComboFieldEditor mergeMode = new ComboFieldEditor(UIPreferences.MERGE_MODE, UIText.GitPreferenceRoot_MergeModeLabel, MERGE_MODE_NAMES_AND_VALUES, mergeGroup);
    mergeMode.getLabelControl(mergeGroup).setToolTipText(UIText.GitPreferenceRoot_MergeModeTooltip);
    addField(mergeMode);
    updateMargins(mergeGroup);
    Group blameGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    GridDataFactory.fillDefaults().grab(true, false).span(GROUP_SPAN, 1).applyTo(blameGroup);
    blameGroup.setText(UIText.GitPreferenceRoot_BlameGroupHeader);
    addField(new BooleanFieldEditor(UIPreferences.BLAME_IGNORE_WHITESPACE, UIText.GitPreferenceRoot_BlameIgnoreWhitespaceLabel, blameGroup));
    updateMargins(blameGroup);
    Group secureGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    GridDataFactory.fillDefaults().grab(true, false).span(GROUP_SPAN, 1).applyTo(secureGroup);
    secureGroup.setText(UIText.GitPreferenceRoot_SecureStoreGroupLabel);
    addField(new BooleanFieldEditor(UIPreferences.CLONE_WIZARD_STORE_SECURESTORE, UIText.GitPreferenceRoot_SecureStoreUseByDefault, secureGroup));
    updateMargins(secureGroup);
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DirectoryFieldEditor(org.eclipse.jface.preference.DirectoryFieldEditor) BooleanFieldEditor(org.eclipse.jface.preference.BooleanFieldEditor) ComboFieldEditor(org.eclipse.jface.preference.ComboFieldEditor) CoreException(org.eclipse.core.runtime.CoreException) IStringVariableManager(org.eclipse.core.variables.IStringVariableManager) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor) File(java.io.File)

Example 15 with IStringVariableManager

use of org.eclipse.core.variables.IStringVariableManager in project generator by mybatis.

the class AbstractGeneratorComposite method getWorkspaceResource.

private IResource getWorkspaceResource() {
    String path = txtFileName.getText();
    if (path.length() > 0) {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        try {
            if (path.startsWith("${workspace_loc:")) {
                // $NON-NLS-1$
                IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
                path = manager.performStringSubstitution(path, false);
            }
            File f = new File(path);
            IFile[] files;
            files = root.findFilesForLocationURI(f.toURI());
            if (files.length <= 0) {
                return null;
            }
            return files[0];
        } catch (CoreException e) {
            return null;
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IStringVariableManager(org.eclipse.core.variables.IStringVariableManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

IStringVariableManager (org.eclipse.core.variables.IStringVariableManager)15 CoreException (org.eclipse.core.runtime.CoreException)14 File (java.io.File)9 IFile (org.eclipse.core.resources.IFile)6 IPath (org.eclipse.core.runtime.IPath)4 IResource (org.eclipse.core.resources.IResource)3 IProject (org.eclipse.core.resources.IProject)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 Path (org.eclipse.core.runtime.Path)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IBinaryObject (org.eclipse.cdt.core.IBinaryParser.IBinaryObject)1 IManagedCommandLineInfo (org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo)1 IContainer (org.eclipse.core.resources.IContainer)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 BooleanFieldEditor (org.eclipse.jface.preference.BooleanFieldEditor)1 ComboFieldEditor (org.eclipse.jface.preference.ComboFieldEditor)1 DirectoryFieldEditor (org.eclipse.jface.preference.DirectoryFieldEditor)1 IntegerFieldEditor (org.eclipse.jface.preference.IntegerFieldEditor)1