use of org.eclipse.ui.views.navigator.ResourceComparator in project jbosstools-hibernate by jbosstools.
the class HibernatePropertiesComposite method createSetupAction.
private Runnable createSetupAction() {
return new Runnable() {
@Override
public void run() {
IPath initialPath = getConfigurationFilePath();
int defaultChoice = 0;
if (initialPath != null) {
defaultChoice = 1;
}
MessageDialog dialog = createSetupDialog(HibernateConsoleMessages.ConsoleConfigurationMainTab_setup_configuration_file, HibernateConsoleMessages.ConsoleConfigurationMainTab_do_you_want_to_create_new_cfgxml, defaultChoice);
int answer = dialog.open();
IPath cfgFile = null;
if (answer == 0) {
// create new
cfgFile = handleConfigurationFileCreate();
} else if (answer == 1) {
// use existing
cfgFile = handleConfigurationFileBrowse();
}
if (cfgFile != null) {
HibernatePropertiesComposite.this.cfgFile.setText(makeClassPathRelative(cfgFile).toString());
}
}
protected IPath makeClassPathRelative(IPath cfgFile) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource res = root.findMember(cfgFile);
if (res != null && res.exists() && res.getType() == IResource.FILE) {
IPackageFragmentRoot[] allPackageFragmentRoots = getSourcePackageFragmentRoots();
for (IPackageFragmentRoot iPackageFragmentRoot : allPackageFragmentRoots) {
if (iPackageFragmentRoot.getResource().getFullPath().isPrefixOf(cfgFile)) {
cfgFile = cfgFile.removeFirstSegments(iPackageFragmentRoot.getResource().getFullPath().segmentCount());
return cfgFile;
}
}
}
return res.getLocation();
}
private MessageDialog createSetupDialog(String title, String question, int defaultChoice) {
return new MessageDialog(getShell(), title, null, question, MessageDialog.QUESTION, new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_create_new, HibernateConsoleMessages.ConsoleConfigurationMainTab_use_existing, IDialogConstants.CANCEL_LABEL }, defaultChoice);
}
private IPath handleConfigurationFileBrowse() {
IPath[] paths = chooseFileEntries();
if (paths != null && paths.length == 1) {
return paths[0];
}
return null;
}
public IPath[] chooseFileEntries() {
TypedElementSelectionValidator validator = new TypedElementSelectionValidator(new Class[] { IFile.class }, false);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource focus = getConfigurationFilePath() != null ? root.findMember(getConfigurationFilePath()) : null;
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider() {
public Object[] getElements(Object element) {
IPackageFragmentRoot[] sourcePackageFragmentRoots = getSourcePackageFragmentRoots();
IResource[] ress = new IResource[sourcePackageFragmentRoots.length];
for (int i = 0; i < sourcePackageFragmentRoots.length; i++) {
ress[i] = sourcePackageFragmentRoots[i].getResource();
}
return ress;
}
});
dialog.setValidator(validator);
dialog.setAllowMultiple(false);
dialog.setTitle(HibernateConsoleMessages.ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file);
dialog.setMessage(HibernateConsoleMessages.ConsoleConfigurationMainTab_choose_file_to_use_as_hibernate_cfg_xml);
dialog.addFilter(new FileFilter(new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_cfg_xml }, null, true, false));
dialog.setInput(root);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setInitialSelection(focus);
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
IPath[] res = new IPath[elements.length];
for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i];
res[i] = elem.getFullPath();
}
return res;
}
return null;
}
private IPath handleConfigurationFileCreate() {
NewConfigurationWizard wizard = new NewConfigurationWizard();
wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
wdialog.create();
IWizardPage configPage = wizard.getPage(HibernateConsoleMessages.ConsoleConfigurationMainTab_wizard_page);
if (configPage != null && configPage instanceof NewConfigurationWizardPage) {
((NewConfigurationWizardPage) configPage).setCreateConsoleConfigurationVisible(false);
}
// This opens a dialog
if (wdialog.open() == Window.OK) {
WizardNewFileCreationPage createdFilePath = ((WizardNewFileCreationPage) wizard.getStartingPage());
if (createdFilePath != null) {
// createNewFile() does not creates new file if it was created by wizard (OK was pressed)
return createdFilePath.createNewFile().getFullPath();
}
}
return null;
}
};
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project webtools.sourceediting by eclipse.
the class ProcessorLibraryBlock method addWorkspace.
private void addWorkspace(IStructuredSelection selection) {
IDialogSettings dialogSettings = XSLDebugUIPlugin.getDefault().getDialogSettings();
String lastUsedPath = dialogSettings.get(LAST_WORKSPACE_PATH_SETTING);
IPath lastPath = null;
if (lastUsedPath != null) {
lastPath = Path.fromPortableString(lastUsedPath);
}
// IResource currentResource = getResource();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(tableViewer.getControl().getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(Messages.ProcessorLibraryBlock_WorkspaceFileDialog_Title);
dialog.setMessage(Messages.ProcessorLibraryBlock_WorkspaceFileDialog_Message);
dialog.setValidator(validator);
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IContainer)
return true;
else if (element instanceof IFile) {
IFile file = (IFile) element;
String extension = file.getFileExtension();
if (extension == null)
return false;
// $NON-NLS-1$
return extension.equals("jar");
}
return false;
}
});
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
if (lastPath != null)
dialog.setInitialSelection(lastPath);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setAllowMultiple(true);
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
if (elements.length > 0) {
IProcessorJar[] libs = new IProcessorJar[elements.length];
for (int i = 0; i < elements.length; i++) {
IFile jar = (IFile) elements[i];
libs[i] = JAXPRuntime.createProcessorJar(jar.getFullPath());
}
IProcessorJar[] currentJars = install.getProcessorJars();
IProcessorJar[] newJars = new IProcessorJar[currentJars.length + libs.length];
System.arraycopy(currentJars, 0, newJars, 0, currentJars.length);
System.arraycopy(libs, 0, newJars, currentJars.length, libs.length);
install.setProcessorJars(newJars);
tableViewer.add(libs);
lastPath = libs[0].getPath();
lastPath = lastPath.uptoSegment(lastPath.segmentCount());
dialogSettings.put(LAST_WORKSPACE_PATH_SETTING, lastPath.toPortableString());
}
}
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project tdi-studio-se by Talend.
the class AddResourceAction method run.
/**
* Prompts for a jar to add.
*
* @see IAction#run()
*/
@Override
public void run() {
// ViewerFilter filter = new ArchiveFilter(getSelectedJars());
ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp = new WorkbenchContentProvider();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
dialog.setValidator(validator);
//$NON-NLS-1$
dialog.setTitle(Messages.getString("AddResourceAction.JARSecection"));
//$NON-NLS-1$
dialog.setMessage(Messages.getString("AddResourceAction.ChooseResource"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot().getProject(PluginConstant.COMPONENT_PROJECT));
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
List<ILibEntry> res = new ArrayList<ILibEntry>();
for (int i = 0; i < elements.length; i++) {
IResource elem = (IResource) elements[i];
String name = elem.getName();
if (name.matches("(?i).*\\.(jar)\\b")) {
//$NON-NLS-1$
res.add(new JarLibEntry(elem));
}
if (name.matches("(?i).*\\.(pm)\\b")) {
//$NON-NLS-1$
res.add(new PmLibEntry(elem));
}
}
if (res.size() > 0) {
ILibEntry[] entries = new ILibEntry[res.size()];
getViewer().addEntries(res.toArray(entries));
}
}
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project linuxtools by eclipse.
the class SystemTapOptionsTab method createFileOption.
private void createFileOption(Composite top) {
Composite browseTop = new Composite(top, SWT.NONE);
browseTop.setLayout(new GridLayout(4, false));
browseTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label suppFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
suppFileLabel.setText(Messages.getString("SystemTapOptionsTab.ScriptSelector"));
scriptFile = new Text(browseTop, SWT.BORDER);
scriptFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
scriptFile.addModifyListener(modifyListener);
// $NON-NLS-1$
workspaceBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton"), null);
workspaceBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.ResourceButton"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SuppresionsFile"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
String arg = resource.getFullPath().toString();
scriptFile.setText(workspacePath + arg);
}
}));
// $NON-NLS-1$
fileBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.FileSystem"), null);
fileBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = scriptFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
scriptFile.setText(filePath);
}
}));
Label binaryFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
binaryFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectBinary"));
binaryFile = new Text(browseTop, SWT.BORDER);
binaryFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
binaryFile.addModifyListener(modifyListener);
// $NON-NLS-1$
Button workspaceBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
workspaceBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
String arg = resource.getFullPath().toString();
binaryFile.setText(workspacePath + arg);
}
}));
// $NON-NLS-1$
Button fileBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
fileBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = binaryFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
File file = new File(filePath);
if (file.exists())
binaryFile.setText(filePath);
}
}));
Label outputFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
outputFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectOutput"));
outputFile = new Text(browseTop, SWT.BORDER);
outputFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
outputFile.addModifyListener(modifyListenerOutput);
outputFile.addFocusListener(focusListener);
// $NON-NLS-1$
Button workspaceBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
workspaceBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
String arg = resource.getFullPath().toString();
outputFile.setText(workspacePath + arg);
checkOverwrite();
updateLaunchConfigurationDialog();
}
}));
// $NON-NLS-1$
Button fileBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
fileBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = outputFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
outputFile.setText(filePath);
checkOverwrite();
updateLaunchConfigurationDialog();
}
}));
useColourButton = new Button(browseTop, SWT.CHECK);
// $NON-NLS-1$
useColourButton.setText(Messages.getString("SystemTapOptionsTab.ColourCodes"));
useColourButton.addSelectionListener(selectListener);
useColourButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project linuxtools by eclipse.
the class OpenGCDialog method handleBrowseWorkspace.
protected void handleBrowseWorkspace(String msg, Text text) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(msg);
dialog.setMessage(msg);
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setAllowMultiple(false);
IContainer c = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(this.gcFile);
if (c != null)
dialog.setInitialSelection(c.getProject());
dialog.setValidator(selection -> {
if (selection.length != 1) {
// $NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
}
if (!(selection[0] instanceof IFile)) {
// $NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
}
// $NON-NLS-1$
return new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
});
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
// $NON-NLS-1$ //$NON-NLS-2$
text.setText("${resource_loc:" + resource.getFullPath() + "}");
}
}
Aggregations