I'm facing a problem and want to ask for a solution.
I'm working on an eclipse plugin project, in which an editor for a type of resource file is required. The resource file has similar structure like CSV file. My idea is to provide user the option to edit this type of file both in plain text format and also in an SWT table. Plain text is required for examining data and table provides more flexibility to editing such as sorting by column.
I have been able to create a MultiPageEditorPart, with one page of org.eclipse.ui.editors.text.TextEditor, and another page with a org.eclipse.swt.widgets.Table and several other widgets like search bar. The content of the resource file can be shown in the TextEditor, can also be edited and saved. On the other hand, the content can be loaded in the table too, sorting and searching all work good.
The problem is: when I edit a cell in the table, I want the change also reflected in the TextEditor, and vice versa. Since the resource file can be very large, I want the saving action happen only on the TextEditor, i.e. I don't want any modification in the table directly stored to resource file, but to mark the file dirty, but I can't figure out how. How can I for example get the content of EditorInput, check it line by line, and modify it outside TextEditor?
Or, are there more efficient ways to do this? Can anyone give any hints?
The IDocument used by the TextEditor gives you access to the document contents. Get this with something like:
IDocumentProvider provider = editor.getDocumentProvider();
IEditorInput input = editor.getEditorInput();
IDocument document = provider.getDocument(input);
IDocument has many methods for accessing lines such as:
int getLineOffset(int line);
int getLineLength(int line);
and methods for modify the text:
void replace(int offset, int length, String text);
Related
,
I read lots of answer here and learn something about this topic but I need more help.Some pages in my project are getting the html(page body) from database.For my controls I use resx files and it works great, but now I need save the html values with multi-lang in my database.
I have a admin panel for my project and I edit sometimes the html or text or pictures in my editor and save it back to DB.I cache the html values in my website and get better performance for my project.But the html text parts is yet in my default lang I will create multi-lang.
I thought of a few possible solutions,
First solution was copying all of the same HTML data and create for all lang one by one
First solution problem : But later this doesnt make sense If I copy the values and create for other lang, then I had be repeating unnecessarily in my database the html values.
My second solution was like this :
this I hid it in the normal way in my DB (only a part of html in one column)
<li>Hello World</li>
<li>Hello Me</li>
Solution :
<li>[HelloWorld]</li>
<li>[HelloMe]</li>
string newHtmlValue = oldValue.ReplaceByLang("[HelloWorld]", GetCulture();,"Hallo Welt");
***// GetCulture(); return for this example german !
I create a new table for the replace text like the key is [HelloWorld]
1(ROW)- [HelloWorld] eng Hello World
2(ROW)- [HelloWorld] german Hallo Welt
3(ROW)- [HelloWorld] fr bonjour tout le monde
and in my project I select the right html value by culture lang.
Now my question is have you any better idea ?
I hope I've been clear and not messy, but if you need more informations I'll be glad to tell you more.Sorry for english.
I would prefer to store all your localized string in single repository like - DB or Satellite assembly.
For Example if you choose DB as repository - Define 3 tables (minimal structure)
1.Locale - Define your locale
2.Resourcemaster - Define your source string and reference Key and this key should be unique in you application and define a standard format like Module_Control_Section ..
3.LocalizedResource - Define your localized sting of Resourcemaster with Locale Key. Foreign key with ResourceMaster and Locale
In front End you can resole any string like control , Html string with localized string and Unique reference key.
Also Implement UI Caching / API caching for better performance.
Regards
Abdul
How do you Edit a (binary EBCDIC) Mainframe file in the RecordEditor with out a Cobol Copybook.
How do you generate Java code to read the file using the RecordEditor.
Note: This is an attempt to split a question that is far to broad to give meaningful answer to
into a series of simpler Question and Answer's.
Try and avoid editing a binary file with a Cobol Copybook if at all possible. This should only be attempted as a last resort !!!.
Try and get
that Cobol copybook (or some field layout document) for the file !!!
Some general advise:
It is feasible when dealing with 10 / 20 fields in a record but not if there a thousands of fields in a Record.
Take your time do not rush the process. Try and get each step correct before moving on
Finally upgrade to the latest version of the RecordEditor (currently 0.98.4)
This process will also work for normal Text file as well
RecordEditor Layout Wizard
To start the wizard select option Record Layouts >>> Layout Wizard.
File Structure screen
The file structure screen has 3 purposes:
Get the File structure - It could be Fixed Width, VB, Windows/Unix Text file
Get the Record-Length (if it is a fixed width file).
Get the font (character-set / encoding)
The RecordEditor will try and work this out for you
Field Selection Screen
The RecordEditor will try and work out where fields start and end but
it is not perfect. You need to carefully check and correct its choices
On this screen, the fields are displayed in alternating colors
you create/delete a field by clicking on
use the Clear Fields button clear all the fields
you can change what field-types to search for using the various check box's (e.g. Mainframe Zones Decimal)
The Add Fields will do another field search
Field Definition screen
On this screen you define the field names and Types. You may need to go back to the **Field Selection Screen* to adjust the fields
Editing the file
Once the Record Layout has been defined, it can be used on the open file screen
Generating Java code
When editing your file, you can generate java~JRecord code to read the file
by selecting Generate >>> Java >>> ....
You can the enter a package-id + generate options:
and finally your sample java code is generated to read / write the
file.
I would like to know, how can i reuse one template (with one page inside and some variables) multiple times a XWPFDocument object.
My idea is:
load the template once in a XWPFDocument as an template-object
clone/create/copy the template-object with all his styles and headers etc
fill the clone with content
add this clone to the destination-XWPFDocument
I got this work for one single page only.
When i try to clone/create/copy the template-object it will lose all his style informations.
How to copy a paragraph of .docx to another .docx withJava and retain the style
How to copy some content in one .docx to another .docx , using POI without losing format?
POI probably does not support this out of the box, but I have done a similar thing in my project poi-mail-merge, it works with the underlying XML to repeatedly replace markers in a template Microsoft Word document and combine the results into one resulting document.
So it basically duplicates the template document multiple times into the resulting document.
See here for how I do it there, basically I work on the XML body text and do replacements/changes there and then append it onto the result document.
POI Mail Merge propably helps in other cases but in my case it doesn't work.
My Workaround is to update my Template-XWPFDocument to the needed structure first, save it temporarily and read it back into a XWPFDocument-object.
Here the steps:
Read the template-file into a XWPFDocument
Read the records from data-file e.g. csv
Calculate the numbers of pages related to the data-records
Get the Bodyelements-Objects from the Template-XWPFDocument
Create new Bodyelements (depending to the numbers of pages) in the Template-XWPFDocument and replace them with the same Objects that we get before
Save the updated Template-XWPFDocument temporarily
Read the temporarily saved Template into a XWPFDocument
Replace all placeholder and fill them with your CSV-Data
Hope this helps somebody
I would like to let the user choose a save option while selecting a file type. The selection works fine as in the below example. However after the user has selected a file type to be saved, I have not found a possibility to check which type he has selected.
Please note: Both file type choices have the same extension. The difference between the two is the display name.
var fsp = new FileSavePicker();
fsp.FileTypeChoices.Add("my file type", new List<string> {".extension"});
fsp.FileTypeChoices.Add("my file type (special)",new List<string>{".extension"});
StorageFile sf = await fsp.PickSaveFileAsync();
// How to know here which FileTypeChoice the user has selected
Has anyone an idea how I can get the selected FileTypeChoice?
I don't think you can. The problem here is that the only difference between the two is the display name. I'd highly recommend using similar but distinct file extensions. What you have here is a distinction without any evidence. This makes it impossible for either the system or the user to distinguish between Type A and Type B.
I have a custom content type with 3 FileFields (plone.app.blob.field.FileField) and I want to get their url's, so i can put them on my custom view and people will be able to download these files.
However, when using Clouseau to test and debug, I call :
context.getFirst_file().absolute_url()
Where getFirst_file() is the accessor to the first file (field called 'first_file').
The url returned is 'http://foo/.../eat.00001', where 'eat.00001' is the object of my custom type that contains the file fields...
The interesting thing is, if I call:
context.getFirst_file().getContentType()
It returns 'application/pdf', which is correct since it's a pdf file.
I'm pretty lost here, any help is appreciated. Thanks in advance!
File fields do not support a absolute_url method; instead, through acquisition you inherit the method from the object itself, hence the results you see. Moreover, calling getFirst_field() will return the actual downloadable contents of the field, not the field itself which could provide such information.
Instead, you should use the at_download script appended to the object URL, followed by the field id:
First File
You can also re-use the Archetypes widget for the field, by passing the field name to the widget method:
<metal:field use-macro="python:context.widget('first_field', mode='view')">
First File
</metal:field>
This will display the file size, icon (if available), the filename and the file mime type.
In both these examples, I assumed the name of the field is 'first_field'.