use of org.eclipse.core.resources.IContainer in project eclipse-pmd by acanda.
the class AddRuleSetConfigurationController method browseContainer.
private Optional<IResource> browseContainer(final Shell shell, final IContainer container) {
final FileSelectionDialog dialog = new FileSelectionDialog(shell);
dialog.setMessage("Choose a PMD rule set configuration:");
dialog.setValidator(new ISelectionStatusValidator() {
@Override
public IStatus validate(final Object[] selection) {
IStatus result = new Status(IStatus.OK, PMDPlugin.ID, "");
if (selection.length == 1 && !(selection[0] instanceof IContainer)) {
final IResource resource = (IResource) selection[0];
final String configuration = resource.getLocation().toOSString();
try {
new RuleSetFactory().createRuleSet(configuration);
} catch (final RuleSetNotFoundException | IllegalArgumentException e) {
// the rule set location is invalid
result = new Status(IStatus.WARNING, PMDPlugin.ID, resource.getName() + " is not a valid PMD rule set configuration");
}
} else {
result = new Status(IStatus.WARNING, PMDPlugin.ID, "");
}
return result;
}
});
dialog.setInput(container);
if (dialog.open() == Window.OK) {
return Optional.of((IResource) dialog.getFirstResult());
}
return Optional.absent();
}
use of org.eclipse.core.resources.IContainer in project bndtools by bndtools.
the class WorkspaceMainPart method initialize.
@Override
public void initialize(final IManagedForm form) {
super.initialize(form);
final Composite container = (Composite) getSection().getClient();
// create a layout stack and the first visible component will be an empty component with "waiting" message
// this will be replaced by real composite once workspace completes
final StackLayout stackLayout = new StackLayout();
container.setLayout(stackLayout);
Composite labelParent = new Composite(container, SWT.NONE);
FillLayout fillLayout = new FillLayout();
fillLayout.marginHeight = fillLayout.marginWidth = 10;
labelParent.setLayout(fillLayout);
if (!Central.isWorkspaceInited()) {
Label label = new Label(labelParent, SWT.NONE);
label.setText("Workspace is loading, please wait...");
label.setBackground(container.getBackground());
label.setForeground(container.getForeground());
}
stackLayout.topControl = labelParent;
container.layout();
Central.onWorkspaceInit(new Success<Workspace, Void>() {
@Override
public Promise<Void> call(Promise<Workspace> resolved) throws Exception {
final Deferred<Void> completion = new Deferred<>();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
IFile buildFile = Central.getWorkspaceBuildFile();
if (buildFile == null)
return;
Composite contents = new Composite(container, SWT.NONE);
if (!mainFile) {
ImageHyperlink link = form.getToolkit().createImageHyperlink(contents, SWT.CENTER);
link.setText("Open main build.bnd file.");
link.setImage(bndFileImg);
link.addHyperlinkListener(new FileOpenLinkListener(buildFile.getFullPath()));
} else {
IResource[] extFiles;
IContainer cnfDir = buildFile.getParent();
IFolder extDir = cnfDir.getFolder(new Path("ext"));
if (extDir.exists())
extFiles = extDir.members();
else
extFiles = new IResource[0];
if (extFiles.length > 0) {
for (IResource extFile : extFiles) {
if (extFile.getType() == IResource.FILE && "bnd".equalsIgnoreCase(extFile.getFileExtension())) {
ImageHyperlink link = form.getToolkit().createImageHyperlink(contents, SWT.CENTER);
link.setText("Open " + extFile.getName());
link.setImage(extFileImg);
link.addHyperlinkListener(new FileOpenLinkListener(extFile.getFullPath()));
}
}
} else {
createMissingExtsWarningPanel(contents, form.getToolkit(), extDir.getFullPath());
}
}
stackLayout.topControl = contents;
container.layout();
completion.resolve(null);
} catch (Exception e) {
Plugin.error(Collections.singletonList(e.getMessage()));
completion.fail(e);
}
}
});
return completion.getPromise();
}
});
}
use of org.eclipse.core.resources.IContainer in project bndtools by bndtools.
the class GenerateIndexCommandHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structSel = (IStructuredSelection) selection;
Object element = structSel.getFirstElement();
if (element != null && element instanceof IContainer) {
NewIndexWizard wizard = new NewIndexWizard();
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
wizard.init(workbenchWindow.getWorkbench(), structSel);
WizardDialog dialog = new WizardDialog(workbenchWindow.getShell(), wizard);
dialog.open();
}
}
return null;
}
use of org.eclipse.core.resources.IContainer in project yamcs-studio by yamcs.
the class ResourceAndContainerGroup method setContainerFullPath.
/**
* Sets the value of this page's container.
*
* @param path
* Full path to the container.
*/
public void setContainerFullPath(final IPath path) {
IResource initial = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (initial != null) {
if (!(initial instanceof IContainer)) {
initial = initial.getParent();
}
_containerGroup.setSelectedResource(initial);
}
validateControls();
}
use of org.eclipse.core.resources.IContainer in project yamcs-studio by yamcs.
the class FileUtil method writeTextFile.
/**
* Write a text file.
*
* @param filePath
* path of the file. It can be an absolute path or a relative path to the OPI that contains the specified
* widget. If it is an absolute path, it can be either<br>
* a workspace path such as <code>/BOY Examples/Scripts/myfile.xml</code><br>
* a local file system path such as <code>C:\myfile.xml</code><br>
* or an URL path such as <code>http://mysite.com/myfile.xml</code>.
* @param inWorkspace
* true if the file path is a workspace file path. Otherwise, it will be recognized as a local file
* system file.
* @param widget
* a widget in the OPI, which is used to provide relative path reference. It can be null if the path is
* an absolute path.
* @param text
* the text to be written to the file.
* @param append
* true if the text should be appended to the end of the file.
* @throws Exception
* if error happens.
*/
public static void writeTextFile(String filePath, boolean inWorkspace, AbstractBaseEditPart widget, String text, boolean append) throws Exception {
IPath path = FileUtil.buildAbsolutePath(filePath, widget);
if (inWorkspace) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
String projectName = path.segment(0);
IProject project = root.getProject(projectName);
if (!(project.exists())) {
project.create(new NullProgressMonitor());
}
project.open(new NullProgressMonitor());
IFolder folder = null;
for (int i = 1; i < path.segmentCount() - 1; i++) {
if (i == 1)
folder = project.getFolder(path.segment(i));
else
folder = folder.getFolder(path.segment(i));
if (!(folder.exists())) {
folder.create(true, true, null);
}
}
IContainer container;
if (folder == null)
container = project;
else
container = folder;
IFile file = container.getFile(ResourceUtil.getPathFromString(path.lastSegment()));
if (file.exists()) {
StringBuilder sb = new StringBuilder();
if (append) {
sb.append(FileUtil.readTextFile(filePath, widget));
}
sb.append(text);
file.setContents(new ByteArrayInputStream(sb.toString().getBytes("UTF-8")), true, false, // $NON-NLS-1$
null);
} else {
File sysFile = file.getLocation().toFile();
BufferedWriter writer = new BufferedWriter(// $NON-NLS-1$
new OutputStreamWriter(new FileOutputStream(sysFile, append), "UTF-8"));
writer.write(text);
writer.flush();
writer.close();
}
} else {
BufferedWriter writer = new BufferedWriter(// $NON-NLS-1$
new OutputStreamWriter(new FileOutputStream(path.toString(), append), "UTF-8"));
writer.write(text);
writer.flush();
writer.close();
}
}
Aggregations