Skip to content

Commit

Permalink
open BndEditor on DoubleClick for non-local processors
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Rueger <[email protected]>
  • Loading branch information
chrisrueger committed Dec 20, 2024
1 parent 28f09f4 commit 03c37f1
Showing 1 changed file with 55 additions and 4 deletions.
59 changes: 55 additions & 4 deletions bndtools.core/src/bndtools/editor/BndSourceEffectivePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.text.Document;
Expand All @@ -19,6 +23,9 @@
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
Expand All @@ -30,8 +37,11 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
Expand All @@ -40,6 +50,7 @@
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.FindReplaceAction;

import aQute.bnd.build.model.BndEditModel;
Expand Down Expand Up @@ -161,6 +172,42 @@ private void createTableViewer(IManagedForm managedForm, Composite body) {
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setInput(getTableData());

tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = tableViewer.getStructuredSelection();
String[] selectedItem = (String[]) selection.getFirstElement();
if (selectedItem != null) {
String fpath = selectedItem[2];
if (fpath == null || fpath.isBlank()) {
return;
}

// System.out.println("Double-clicked on: " +
// fpath.toString());
IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
.getRoot();

File file = new File(fpath);
org.eclipse.core.runtime.IPath path = new Path(file.getAbsolutePath());
IFile iFile = root.getFileForLocation(path);
if (iFile == null) {
// File is not in the workspace. You cannot directly get
// an IFile for it.
}
IEditorInput input = new FileEditorInput(iFile);
try {
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.openEditor(input, BndEditor.WORKSPACE_EDITOR);
} catch (PartInitException e) {
throw Exceptions.duck(e);
}
}
}
});

}


Expand Down Expand Up @@ -246,6 +293,7 @@ private void update() {
String text = print(editModel);
viewer.setDocument(new Document(text));
styledText.setFocus();
tableViewer.setInput(getTableData());
} catch (Exception e) {
throw Exceptions.duck(e);
}
Expand Down Expand Up @@ -274,7 +322,7 @@ private void createColumns() {
"key", "value", "path"
};
int[] bounds = {
100, 200, 200
200, 300, 300
};

for (int i = 0; i < titles.length; i++) {
Expand Down Expand Up @@ -330,12 +378,15 @@ private Object[] getTableData() {
String key = prop.key();
String value = p.getProperty(key);
String path = "";
if (!prop.isLocalTo(p)) {
if (!prop.isLocalTo(editModel.getOwner())) {
File propertiesFile = prop.processor()
.getPropertiesFile();
if (propertiesFile != null) {
path = propertiesFile.getAbsolutePath();

path = propertiesFile.getPath();
// .replaceAll(prop.processor()
// .getBase()
// .getPath(), "")
// .substring(1);
}
}
result[index] = new String[] {
Expand Down

0 comments on commit 03c37f1

Please sign in to comment.