use of org.eclipse.ui.model.WorkbenchContentProvider 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.model.WorkbenchContentProvider in project eclipse-cs by checkstyle.
the class ProjectConfigurationEditor method createEditorControl.
/**
* {@inheritDoc}
*/
@Override
public Control createEditorControl(Composite parent, final Shell shell) {
Composite contents = new Composite(parent, SWT.NULL);
contents.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
contents.setLayout(layout);
Label lblConfigName = new Label(contents, SWT.NULL);
lblConfigName.setText(Messages.CheckConfigurationPropertiesDialog_lblName);
GridData gd = new GridData();
lblConfigName.setLayoutData(gd);
mConfigName = new Text(contents, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
mConfigName.setLayoutData(gd);
Label lblConfigLocation = new Label(contents, SWT.NULL);
lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation);
gd = new GridData();
lblConfigLocation.setLayoutData(gd);
Composite locationComposite = new Composite(contents, SWT.NULL);
locationComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
layout = new GridLayout(2, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
locationComposite.setLayout(layout);
mLocation = new Text(locationComposite, SWT.LEFT | SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
mLocation.setLayoutData(gd);
mBtnBrowse = new Button(locationComposite, SWT.PUSH);
mBtnBrowse.setText(Messages.ProjectConfigurationLocationEditor_btnBrowse);
mBtnBrowse.setLayoutData(new GridData());
mBtnBrowse.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(Messages.ProjectConfigurationLocationEditor_titleSelectConfigFile);
dialog.setMessage(Messages.ProjectConfigurationLocationEditor_msgSelectConfigFile);
dialog.setBlockOnOpen(true);
dialog.setAllowMultiple(false);
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setValidator(new ISelectionStatusValidator() {
@Override
public IStatus validate(Object[] selection) {
if (selection.length == 1 && selection[0] instanceof IFile) {
return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, IStatus.ERROR, new String(), null);
}
return new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR, new String(), null);
}
});
if (Window.OK == dialog.open()) {
Object[] result = dialog.getResult();
IFile checkFile = (IFile) result[0];
mLocation.setText(checkFile.getFullPath().toString());
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// NOOP
}
});
Label lblDescription = new Label(contents, SWT.NULL);
lblDescription.setText(Messages.CheckConfigurationPropertiesDialog_lblDescription);
gd = new GridData();
gd.horizontalSpan = 2;
lblDescription.setLayoutData(gd);
mDescription = new Text(contents, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.VERTICAL);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 2;
gd.widthHint = 300;
gd.heightHint = 100;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
mDescription.setLayoutData(gd);
Group advancedGroup = new Group(contents, SWT.NULL);
advancedGroup.setText(Messages.RemoteConfigurationEditor_titleAdvancedOptions);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
advancedGroup.setLayoutData(gd);
advancedGroup.setLayout(new GridLayout(2, false));
mChkProtectConfig = new Button(advancedGroup, SWT.CHECK);
mChkProtectConfig.setText(Messages.ProjectConfigurationEditor_chkProtectConfigFile);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
mChkProtectConfig.setLayoutData(gd);
if (mWorkingCopy.getName() != null) {
mConfigName.setText(mWorkingCopy.getName());
}
if (mWorkingCopy.getLocation() != null) {
mLocation.setText(mWorkingCopy.getLocation());
}
if (mWorkingCopy.getDescription() != null) {
mDescription.setText(mWorkingCopy.getDescription());
}
mChkProtectConfig.setSelection(Boolean.valueOf(mWorkingCopy.getAdditionalData().get(ExternalFileConfigurationType.KEY_PROTECT_CONFIG)).booleanValue());
return contents;
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project egit by eclipse.
the class RevertFailureDialog method createCustomArea.
@Override
protected Control createCustomArea(Composite parent) {
if (reasons == null || reasons.isEmpty())
return null;
Composite fileArea = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).applyTo(fileArea);
GridLayoutFactory.fillDefaults().applyTo(fileArea);
TreeViewer viewer = new TreeViewer(fileArea);
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());
viewer.setContentProvider(new WorkbenchContentProvider() {
@Override
public Object[] getElements(Object element) {
return ((Collection) element).toArray();
}
});
final IStyledLabelProvider styleProvider = new WorkbenchStyledLabelProvider() {
@Override
public StyledString getStyledText(Object element) {
// supported
if (element instanceof RevertFailure)
return ((RevertFailure) element).getStyledText(element);
if (element instanceof Path)
return ((Path) element).getStyledText(element);
return super.getStyledText(element);
}
};
viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
viewer.setComparator(new ViewerComparator());
Map<MergeFailureReason, RevertFailure> failures = new HashMap<>();
for (Entry<String, MergeFailureReason> reason : reasons.entrySet()) {
RevertFailure failure = failures.get(reason.getValue());
if (failure == null) {
failure = new RevertFailure(reason.getValue());
failures.put(reason.getValue(), failure);
}
failure.add(reason.getKey());
}
viewer.setInput(failures.values());
return fileArea;
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project tdq-studio-se by Talend.
the class SQLTextEditor method performSaveAs.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#performSaveAs(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
// PTODO qzhang correct save the sql file. for bug 3860.
Shell shell = getSite().getShell();
final IEditorInput input = getEditorInput();
IDocumentProvider provider = getDocumentProvider();
IEditorInput newInput;
if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
super.performSaveAs(progressMonitor);
return;
}
ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp = new WorkbenchContentProvider();
FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp);
if (dialog.open() == Window.CANCEL) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
}
return;
}
Object elements = dialog.getResult()[0];
// ADD xqliu 2010-03-08 feature 10675
IResource elem = (IResource) elements;
if (elem instanceof IFolder) {
IPath filePath = ((IFolder) elem).getFullPath();
filePath = filePath.append(dialog.getFileName() + DEFAULT_FILE_EXTENSION);
if (filePath == null) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
}
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFile file = workspace.getRoot().getFile(filePath);
newInput = new FileEditorInput(file);
if (provider == null) {
// editor has programmatically been closed while the dialog was open
return;
}
boolean success = false;
try {
provider.aboutToChange(newInput);
// MOD qiongli 2011-4-21 bug 20205.after creating property file,file name is changed(contain version
// info),so reset'newInput'.
file = createIFile(file, getViewer().getDocument().get());
newInput = new FileEditorInput(file);
success = true;
} catch (CoreException x) {
final IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
String title = "The file save failure.";
String msg = "The file save failure.";
MessageDialog.openError(shell, title, msg);
}
} finally {
provider.changed(newInput);
if (success) {
setInput(newInput);
}
}
if (progressMonitor != null) {
progressMonitor.setCanceled(!success);
}
}
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project whole by wholeplatform.
the class MergeResourcesAction method performWorkspaceResourceSelection.
protected IEntity performWorkspaceResourceSelection(Shell shell, IEntity entity) {
IResource input;
if (Matcher.matchImpl(ArtifactsEntityDescriptorEnum.Workspace, entity.wGetParent()))
input = ResourcesPlugin.getWorkspace().getRoot();
else {
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
ArtifactsWorkspaceUtils.bindPath(entity.wGetParent(), bm, false);
input = (IResource) (bm.wIsSet("folder") ? bm.wGetValue("folder") : bm.wGetValue("project"));
}
IJavaElement javaInput = JavaCore.create(input);
LabelProvider labelProvider = javaInput != null ? new JavaElementLabelProvider() : new WorkbenchLabelProvider();
ITreeContentProvider contentProvider = javaInput != null ? new StandardJavaElementContentProvider() : new WorkbenchContentProvider();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, labelProvider, contentProvider);
dialog.setInput(javaInput != null ? javaInput : input);
dialog.setTitle(SELECT_RESOURCE_MSG);
dialog.setMessage("Choose a resource");
if (javaInput != null)
dialog.addFilter(new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
try {
return !(element instanceof IPackageFragmentRoot) || ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE;
} catch (Exception e) {
return false;
}
}
});
if (dialog.open() != IDialogConstants.OK_ID)
return NullEntity.instance;
IEntity result = null;
for (Object resource : dialog.getResult()) {
IEntity artifactsPath;
if (resource instanceof IJavaElement) {
IJavaElement toJavaElement = (IJavaElement) resource;
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toJavaElement);
} else {
IResource toResource = (IResource) resource;
IJavaElement parentJavaElement = JavaCore.create(toResource.getParent());
if (javaInput == null || parentJavaElement == null)
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(input, toResource);
else
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toResource);
}
result = result == null ? artifactsPath : EntityUtils.merge(result, artifactsPath, createEntityComparator(), false);
}
int index = Matcher.match(ArtifactsEntityDescriptorEnum.Workspace, result) ? result.wIndexOf(ArtifactsFeatureDescriptorEnum.projects) : result.wIndexOf(ArtifactsFeatureDescriptorEnum.artifacts);
IEntity tree = result.wGet(index);
result.wRemove(index);
return tree;
}
Aggregations