JFace TreeViewer restore selection - eclipse-rcp

I'm doing my first RCP example using the TreeViewer for directory browsing.
My work did start from the example http://www.ibm.com/developerworks/opensource/library/os-ecgui1/
For the TreeViewer of file entries I want to make the last selection persistent
to open the viewer by the same selection next time.
From the selected file I catched the path and store/retrieve this single string.
On reopening I traverse the ITreeContentProvider and find the corresponding
File node (and capture the nodes in between).
Next I use
window.getTree().setSelection(new StructuredSelection(target));
with target as a list of Files holding the path.
This works for the top level directories under C:
But restoring a deeper path fails. The next level is initially not
expanded and fails in the AbstractTreeViewer.setSelectionToWidget().
My feeling is that I do not handle the setSelection() parameter well
but I found no suitable example.
Do you have a simple example for me showing how to restore such
a path selection?
thanks in advance
Wolfgang R.

I've found it. The used example code has a small bug.
public class FileTreeContentProvider implements ITreeContentProvider
{
...
public Object getParent(Object element)
{
// wrong return ((File)element).getParent();
return ((File)element).getParentFile();
}

Related

Eclipse Plugin Development: Adding items to a working set with the path of the item?

Hello,
I'm an eclipse plugin development newbie looking for pointers to get me started on a particular project.
I am trying to build an eclipse plugin that will automatically construct a working set from a text file that simply consists of a list of file path names. The files/items need not share any parent directories. The rough idea is represented in the following diagram:
I am not asking for the solution to this task. That's the over-arching goal. To achieve that goal, I want to conquer some smaller goals first.
With that in mind, here's the smaller goal I'm currently trying to tackle:
In Eclipse, how can I prompt the user for a single file's path, and then add that file to an existing working set?
I'm not sure where to start. Should I work directly off of the existing org.eclipse.ui.workingSets extension point? Or should I use a collection of other extension points? How do I convert strings into something that can be added to a working set? Do I write code that directly modifies the workingsets.xml file?
Even with a much simpler goal, I still feel quite overwhelmed with the vastness of eclipse extension options. There are probably many ways to go about implementing something like this, but I just need one to get started.
Thanks a bunch!
To manipulate working sets you use the working set manager interface IWorkingSetManager. Get this with:
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
From this you can get a particular working by name with:
IWorkingSet workingSet = manager.getWorkingSet("name");
The contents of a working set is an array of IAdaptable objects:
IAdaptable [] contents = workingSet.getElements();
You add to the contents by adding to this array and setting the contents:
IAdaptable [] newContents
.... get new array with old contents + new contents
workingSet.setElements(newContents);
A lot of Eclipse objects implement IAdaptable, for a file in the workspace you would use IFile. You can use dialogs such as ResourceSelectionDialog to select resources from the workspace.

Novacode LineChart type

I have a code that implements a Novacode.LineChart. And the LineChart type which is shown by default is this one:
But I dont want this type of chart, I want it without points, like this:
This is the code where I create the chart:
LineChart c = new LineChart();
c.AddLegend(ChartLegendPosition.Bottom, false);
c.Grouping = Grouping.Stacked;
Anyone knows how can I hide thoose points and show only the lines? Thanks to everyone!!
Your question is shown up while I was searching for the exact same feature. It's probably a bit late but I hope it would be useful for other people in need of this feature.
My so called answer is not more than a few lines of dirty and unmanageable hack so unless you are not in dire need, I do not recommend to follow this way.
I also do not know if is it an approved approach here but I prefer to write the solution step by step so it may help you to grasp the concept and use better methods.
After I have realized that I was unable to use DocX to create a line chart without markers, using currently provided API, I wanted to know what were the differences between actual and desired output. So I saved a copy of .docx file with line chart after I manually edited the chart to expected result.
Before and after the edit
As you may already know, a .docx is a container format and essentially comprised of a few different folders and files. You can open it up with a .zip archive extractor. I used 7-Zip for this task and found chart file at location of /word/charts/chart1.xml but this may differ depending on the file, but you can easily figure it out.
Compared both of chart1.xml files and the difference was, the file without the markers had and extra XML tag with an additional attribute;
<c:marker>
<c:symbol val="none" />
</c:marker>
I had to somehow add this segment of code to chart. I added these up to example code provided by DocX. You can follow up from: DocX/ChartSample.cs at master
This is where the fun begins. Easy part first.
using System.Xml;
using System.Xml.Linq;
using Xceed.Words.NET;
// Create a line chart.
var line_chart = new LineChart();
// Create the data.
var PlaceholderData = ChartData.GenerateRandomDataForLinechart();
// Create and add series
var Series_1 = new Series("Your random chart with placeholder data");
Series_1.Bind(PlaceholderData, "X-Axis", "Y-Axis");
line_chart.AddSeries(Series_1);
// Create a new XmlDocument object and clone the actual chart XML
XmlDocument XMLWithNewTags = new XmlDocument();
XMLWithNewTags.LoadXml(line_chart.Xml.ToString());
I've used XPath Visualizer Tool to determine the XPath query, which is important to know because you can't just add the marker tag to somewhere and expect it to work. Why do I tell this? Because I appended marker tag on a random line and expected it to work. Naive.
// Set a namespace manager with the proper XPath location and alias
XmlNamespaceManager NSMngr = new XmlNamespaceManager(XMLWithNewTags.NameTable);
string XPathQuery = "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser";
string xmlns = "http://schemas.openxmlformats.org/drawingml/2006/chart";
NSMngr.AddNamespace("c", xmlns);
XmlNode NewNode = XMLWithNewTags.SelectSingleNode(XPathQuery, NSMngr);
Now create necessary tags on newly created XML Document object with specified namespace
XmlElement Symbol = XMLWithNewTags.CreateElement("c", "symbol", xmlns);
Symbol.SetAttribute("val", "none");
XmlElement Marker = XMLWithNewTags.CreateElement("c", "marker", xmlns);
Marker.AppendChild(Symbol);
NewNode.AppendChild(Marker);
And we should copy the contents of latest changes to actual XML object. But oops, understandably it is defined as private so it is a read-only object. This is where I thought like "Okay, I've fiddled enough with this. I better find another library" but then decided to go on because reasons.
Downloaded DocX repo, changed this line to
get; set;
recompiled, copied Xceed.Words.NET.dll to both projectfolder/packages and projectfolder/projectname/bin/Debug folder and finally last a few lines were
// Copy the contents of latest changes to actual XML object
line_chart.Xml = XDocument.Parse(XMLWithNewTags.InnerXml);
// Insert chart into document
document.InsertChart(line_chart);
// Save this document to disk.
document.Save();
Is it worth it? I'm not sure but I have learned a few things while working on it. There're probably lots of bad programming practises in this answer so please tell me if you see one. Sorry for meh English.

Typo3 7.2 add file reference to extension model

I'm using Typo 7.2 and am looking for an answer to the following question:
How to add a generated File as FileReference programmatically to an extension model?
First some infos regarding my achievements/tries.
DONE A command controller runs over folders, looks for a specific image and creates a blurred file via GraphicFunctions. The generated file is added to the storage as a standalone simple file and appears in the sys_file table.
$fileObject = $posterStorage->addFile(
$convertResult[3],
$posterStorage->getFolder($blurFolderName),
$newFileName);
PARTIALLY DONE. Now I need to add the generated file as a file reference to my model. The problem is, that I'm able to do this, but only by hacking core - not acceptable - and unable to do it the right way. The model says:
public function addPosterWebBlur(
\TYPO3\CMS\Extbase\Domain\Model\FileReference $posterWebBlur
) {
$this->posterWebBlur->attach($posterWebBlur);
}
So I succeeded by extending the FileReference class:
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
public function setFile(\TYPO3\CMS\Core\Resource\File $falFile) {
$this->$uidLocal = (int)$falFile->getUid();
}
}
The reference does not get established and I just get the following error in the backend:
Table 'db_name.tx_ext_name_domain_model_filereference' doesn't exist.
UPDATE
After integrating the data from Frans in ext_typoscript_setup.txt, the model can be saved, creates an sys_file_reference entry and acts nicely in the backend. But there are a few points open to fulfill all needs:
The sys_file_reference table does not contain a value for table_local, whereas all the entries generated by a backend user hold sys_file as value.
The same applies to l10n_diffsource which holds some binary large object. This entry gets inserted in the sys_file_reference table after saving the record manually via backend.
The pid of the file_reference has to be set via setPid($model->getPid()), is that okay?
The cruser_id is always set to zero. Is this the correct way?
When trying to delete a file (which was added to a model with the backend possibilities) via the file manager, I get a warning, that references to this file exist. This does not apply to the fileReference added programmatically. Also the references listed under the file (when clicking on "Info" for a generated file in the backend file manager) don't get listed. They get listed, when I enter the "sys_file" value in the sys_file_reference table by hand.
As Helmut Hummels example holds additional data, I'm wondering, if I just miss some stuff.
The file reference is used inside an object storage, but as the addImage function only calls objectStorage->attach I think this should be okay and no additional objectStorage actions are neccessary. Correct?
You have to tell the extbase persistence layer to use the correct table. See for instance this example https://github.com/helhum/upload_example/blob/master/ext_typoscript_setup.txt
gr. Frans
Trying to answer 1)
See
https://github.com/helhum/upload_example/blob/master/Configuration/TCA/tx_uploadexample_domain_model_example.php#L128
You should probably check the TCA definition for your posterWebBlur field. Second param of getFileFieldTCAConfig()
TT

How to persist the editor input in e4

In eclipse 3 there was the EditorInput which managed the persistence of editors and its input, but how to manage this with eclipse e4 where editors and views pretty much the same thing ...
Is there any recommended way of doing this or do I have to implemented some kind of editor input registry where I map all editor input objects to some kind of unique key and then after restarting the application I retrieve the editor input object from this registry via the key?
I've seen that I can only put strings into the persisted state of a MPart ...
The getPersistedState() method of any MApplicationElement (which include MPart) returns a Map where you can store any string data that you want to be persisted.
If you want to save objects you will have to use the state location for your plugin in the workspace .metadata. Get the location of that with:
IPath stateLoc = Platform.getStateLocation(bundle);
The path will usually be .metadata/.plugins/<your plugin id>. You can put anything you like it this area, but it is up to you to manage it.
You can use the #Persist annotation to get a method run when a part needs to be persisted:
#Persist
void persist()
{
... save data
}
The persisted state data is saved in the workspace .metadata and only cleared if you specify the -clearPersistedState option when starting your RCP.

AutoCAD: Drag and Drop *.dwg files from my ListBox hosted in Palettset

I'm hosting my .Net ListView control using PalettSet in AutoCAD 2012. The Tag property of ListView items holds the path to *.dwg files. I want to drag from ListView, while picking the dwg file using Item.Tag property and drop it on AutoCAD drawing area and I'm expecting the result would be the drawing would be inserted there just like we normally drag a *.dwg file and drop it on drawing area
I've read about Drag and Drop Blocks using Jig Class and I tried some sample code but using built-in Circle class.
Do I have to first read Blocks from dwg file and then attached to mouse and do the drag and drop operation?
I'm actually confused...
Can someone please guide me? Would really appreciate your replies...
Thanks a bunch....
Farrukh
Finally I solved this, but after some long research and code testing. I wrote code (by reading multiple blogs) which would insert the Block from *.dwg file into current AutoCAD document, but then I realize that many Blocks contains Attributes and some might need to be handled while adding dwg.
So finally, I decided to call INSERT command of AutoCAD, instead writing my own code. Here is the code for other fellows.
Please note that here I'm making it an example while hard-coding dwg file name and path, while in my real application, DWG file path would be read from ListBox.Tag property.
[CommandMethod("InsertDWG")]
static public void SendCmd()
{
string DWGFile = #"D:\sym\1047.DWG";
string InsertCmd = #"_.-INSERT " + DWGFile + '\r' + '\n';
Document doc = Application.DocumentManager.MdiActiveDocument;
doc.SendStringToExecute(InsertCmd, true, false, false);
}
Note: You should keep '\r' + '\n' (Will act as Enter or Carriage Return) with SendStringToExecute() method, or AutoCAD would get the command string, but will wait for user input.
Hope this would be beneficial for someone.
Best regards
Farrukh