My name is Oleg, I'm writing advanced feature - visual comparison of BPEL files.
I would like to use regular editors in "compare" panes (left and right)
As a first step I just want to open two editors (one for each file)
Later I can 'hack' them a little, make new parts green,
deleted parts red etc...
So my problem sounds pretty simple
I have:
- Composite
- Resource which describes .bpel file
And I gotta to open default editor for this Resource in this Composite.
I would appreciate any tips or suggestions!
What did I tried:
I've spent couple days trying to deeper understand GEF,
but after all I didn't found any simple solution for my
simple problem.
People from another project used:
org.eclipse.gmf.runtime.notation.Diagram
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer
diagramGraphicalViewer.setContents(diagram)
but my editor is GEF-based, not GMF-based.
As far as I understood I can't just open editor in composite
I have to use a lot of "extra" stuff - EditorManager,
Workbrenchs, some sites etc. etc.
After all I wrote some straightforward code but it doesn't
work. Likely I wrote it in absolutely wrong way, but let
me quote it just to make clear what do I actually need.
File file2open = new File(new Path("/p1/name2.bpel"), (Workspace) BPELPlugin.getPlugin().getWorkspace()) { };
BPELMultipageEditorPart editorPart = new BPELMultipageEditorPart();
FileEditorInput editorInput = new FileEditorInput(file2open);
EditorDescriptor editorDescriptor = null;
try {
editorDescriptor = (EditorDescriptor)IDE.getEditorDescriptor(file2open);
} catch (PartInitException e) {
e.printStackTrace();
}
WorkbenchPage workbrenchpage = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
EditorSite editorSite = new EditorSite(new EditorReference(workbrenchpage.getEditorManager(), editorInput, editorDescriptor), editorPart, workbrenchpage, editorDescriptor);
try {
editorPart.init(editorSite, editorInput);
} catch (PartInitException e) {
e.printStackTrace();
}
editorPart.createPartControl(mycomposite);
upd: finally I've implemented what I wanted, but not sure if someone else is interested :)
No, there's no good way to open editor in GEF viewer. Keep in mind:
1. "Editor" is Eclipse platform concept. I.e. it is not just a widget but a whole infrastructure. As you said - you would need IEditorSite and so on.
2. GEF figures are "lightweight". You whole GraphicalViewer is a single SWT widget and figures are drawn on it - they don't have OS widgets backing them.
So if you really need to nest an editor in GEF viewer you would have to place the SWT composite on top of viewer and manage its placement.
result of my work http://www.picamatic.com/view/3436443_bpelcompare/ source code: http://dl.dropbox.com/u/49126809/org.eclipse.emf.compare.ui.gef.zip
Related
I am customizing ICN (IBM Content Navigator) 2.0.3 and my requirement is to restrict user to upload files over 10mb and only allowed files are .pdf or .docx.
I know I have to extend / customize the AddContentItemDialog but there is very less detail on exactly how to do it, or any video on it. I'd appreciate if someone could guide.
Thanks
I installed the development environment but I am not sure how to extend the AddContentItemDialog.
public void applicationInit(HttpServletRequest request,
PluginServiceCallbacks callbacks) throws Exception {
}
I want to also know how to roll out the changes to ICN.
This can be easily extended. I would suggest to read the ICN red book for the details on how to do it. But it is pretty standard code.
Regarding rollout the code to ICN, there are two ways:
- If you are using plugin: just replace the Jar file on the server location and restart WAS.
- If you are using EDS: you need to redeploy the web service and restart WAS.
Hope this helps.
thanks
Although there are many ways to do this, one way indeed is tot extend, or augment the AddContentItemDialog as you qouted. After looking at the (rather poor IBM documentation) i figured you could probably use the onAdd event/method
Dojo/Aspect#around allows you to do exactly that, example:
require(["dojo/aspect", "ecm/widget/dialog/AddContentItemDialog"], function(aspect, AddContentItemDialog) {
aspect.around(AddContentItemDialog.prototype, "onAdd", function advisor(original) {
return function around() {
var files = this.addContentItemGeneralPane.getFileInputFiles();
var containsInvalidFiles = dojo.some(files, function isInvalid(file) {
var fileName = file.name.toLowerCase();
var extensionOK = fileName.endsWith(".pdf") || fileName.endsWith(".docx");
var fileSizeOK = file.size <= 10 * 1024 * 1024;
return !(extensionOK && fileSizeOK);
});
if (containsInvalidFiles) {
alert("You can't add that :)");
}else{
original.apply(this, arguments);
}
}
});
});
Just make sure this code gets executed before the actual dialog is opened. The best way to achieve this, is by wrapping this code in a new plugin.
Now on creating/deploying plugins -> The easiest way is this wizard for Eclipse (see also a repackaged version for newer eclipse versions). Just create a new arbitrary plugin, and paste this javascript code in the generated .js file.
Additionally it might be good to note that you're only limiting "this specific dialog" to upload specific files. It would probably be a good idea to also create a requestFilter to limit all possible uses of the addContent api...
I'm currently writing an Eclipse plugin. In it, I want to programmatically open an editor and select a portion of the text. The opened file does not have to be imported into the workspace (that's why I'm using IFileStore in the code below).
I'm using code similar to this:
IFileStore fileStore = EFS.getLocalFileSystem().getStore(localPath);
IEditorPart part = IDE.openEditorOnFileStore(page, fileStore);
final int posStart = ...;
final int posEnd = ...;
part.getEditorSite().getSelectionProvider().setSelection(
new TextSelection(posStart, posEnd - posStart));
For Java files it works fine, but for XML Schema (XSD), it doesn't. The editor opens, but no text is selected.
From debugging, I can tell that the part is of type org.eclipse.wst.xsd.ui.internal.editor.InternalXSDMultiPageEditor, and the selection manager is an org.eclipse.wst.xsd.ui.internal.adt.editor.CommonSelectionManager
I'm targetting Eclipse Mars and Neon, it does not seem to work for both.
What can I do to make it work? Or at least find some further information?
After having a look at the WTP code, this does not seem to be supported at the moment. But I found a workaround by explicitly checking if the editor is a multi part editor:
private static void setSelection(IEditorPart part, TextSelection textSelection) {
if (part instanceof MultiPageEditorPart) {
final MultiPageEditorPart multiPage = (MultiPageEditorPart) part;
for (final IEditorPart subPart : multiPage.findEditors(multiPage.getEditorInput())) {
setSelection(subPart, textSelection);
}
} else {
part.getEditorSite().getSelectionProvider().setSelection(textSelection);
}
}
I was not sure whether it is better to send the selection to all sub parts or only to one specific, but so far sending it to all seems to work.
I writing my own text editor plugin for eclipse. I am now working on my own formatter. Actually, following that link http://wiki.eclipse.org/FAQ_How_do_I_support_formatting_in_my_editor%3F.
I have written my Strategy, I have overridden getContentFormatter in my SourceViewerConfiguration..
As I run my plugin and press Ctrl+Shift+F - and nothing happens.
I think that I'm missing a step here. Should I create a handler or something?
Thanks
Might it be you skipped the last part of the linked page?
Finally, you will need to create an action that invokes the formatter. No generic formatting action is defined by the text infrastructure, but it is quite easy to create one of your own. The action’s run method can simply call the following on the source viewer to invoke the formatter:
sourceViewer.doOperation(ISourceViewer.FORMAT);
What helped me. I have created a handler with the following executors body:
//get the editorPart
if (editorPart != null) {
ITextOperationTarget target = (ITextOperationTarget) editorPart
.getAdapter(ITextOperationTarget.class);
if (target instanceof ISourceViewer) {
ISourceViewer textViewer = (ISourceViewer) target;
((ITextOperationTarget) textViewer)
.doOperation(ISourceViewer.FORMAT);
}
}
Then just create menu items and bind them to the handler.
I want to get the path of current selected file in Eclipse workspace but my project is a simple view plug-in project.
I just want to display the name/path of the file selected as soon as user opens the view.
You get the current selection as mentioned by #Danail Nachev. See http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html for information on working with the selection service.
Once you have the selection, the most common pattern is:
if (selection instanceof IStructuredSelection) {
IStructuredSelection ssel = (IStructuredSelection) selection;
Object obj = ssel.getFirstElement();
IFile file = (IFile) Platform.getAdapterManager().getAdapter(obj,
IFile.class);
if (file == null) {
if (obj instanceof IAdaptable) {
file = (IFile) ((IAdaptable) obj).getAdapter(IFile.class);
}
}
if (file != null) {
// do something
}
}
Edit:
Usually you get an InputStream from the IFile and process it that way. Using some FileSystemProviders or EFS implementations, there might not be a local path to the file.
PW
You can retrieve the current workbench selection using two methods with the following code:
through the Workbench SelectionService
getViewSite().getSelectionProvider().getSelection()
getViewSite().getWorkbenchWindow().getSelectionService()
You can find more information in this article.
Using the global workbench selection is the better approach, because it enables your view to get selection from everywhere, which is something the user might expect (I at least do). Also, almost all of the views in Eclipse (and I don't know exceptions to this rule) are using this approach.
If you absolutely must to tie your view to another view, then you can get all IWorkbenchPage iterate over them and search for the view by its ID and when you find the view, you call get its SelectionProvider to get the selection.
Only by reading this explanation, makes my hair go straight up. Considering that there might be multiple instances of the same view, you can end up with a selection from a random view. I'm not sure whether the user will make sense of how things work, unless you have some clear rules, which exactly view you need. It is up to you.
`
I'm using GWT Richtextbox, But this widget shows values which are simple text or HTML formatted.
Is there any way to show RTF data in a GWT-Richtext or GWT-htmlEditor widget? Or is there a widget in other GWT libraries which will do this?
I don't think so. About year ago we wanted to develop rtf browser on client side and we failed.
There is no GWT-Rtf libraries. You could try to find something written in javascript and then wrap it with JSNI, but I haven't seen such library as well. Someone told me that it might be possible with Activex, but we haven't even tried this method.
What are you trying to achieve? If you want to share documents with an RTF editor like, say, Microsoft Word, you should check to see if that editor can also work with HTML. I know that MS Word can edit HTML.
Alternatively, you might consider transposing RTF into HTML and back again on the server side. There are several Java libraries out there for doing that, and I believe that Flying Saucer is one of them.
You could use RTFEditorKit in combination with HTMLEditorKit to convert between the two server-side or in an applet. This way you can use GWT's rich text editor and output or input RTF.
public static String getHtmlFromRtf(InputStream fi){
Writer sOut = new StringWriter();
DefaultStyledDocument doc = new DefaultStyledDocument();
HTMLEditorKit htmlKit = new HTMLEditorKit();
RTFEditorKit rtf = new RTFEditorKit();
try
{
rtf.read( fi, doc, 0 );
htmlKit.write(sOut, doc, 0, doc.getLength());
}
catch (IOException e)
{
e.printStackTrace();
}
catch (BadLocationException e)
{
e.printStackTrace();
}
return sOut.toString();
}