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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations