IntelliJ IDEA properties - intellij-idea

In my project I'm frequently passing one AccountID in different packages and classes and that accountid is hardcoded wherever it used.
This AccountID may change for some resons in the future. And in order not to go over all files in my my project and replace it, I want to write it in one place.
I heard that there are some properties in IntelliJ where I can do that. I don't know how to google my problem, so if you have any sources, please share.

I think you should use the Properties.class for that purpose.
just write a txt file anywere (I recomend your Resources folder) and name it to "myProperties.properties" for instance
The text in your propertiefile would look like the following:
AccountID = "whateverIDyouWant"
to get the data of your propertiefile call:
Properties props = new Properties();
FileInputStream in = new FileInputStream("G:\\your\\path\\myProperties.properties");
props.load(in);
in.close();
String AccountID = props.getProperty("AccountID");
if your AccountID is an int just parse your string using Integer.parseInt(yourString);
if you want to set your properties through hard code, that can also be done:
props.setProperty("AccountID", "whateverIDyouWant");
Edit:
to create a resources folder, create a folder in your classpath. Afterwards go to the "Project view" in IntelliJ. Rightclick the new folder and select "Mark directory as" -> "Sources Root". Thats how its done.

Related

Create a folder in DXL - DOORS

I am trying to make a script that will copy the contents of one project to another (ie folders and modules) in DXL. To do it, I have seen that there is the create function,
create(string name, string description)
which creates a folder... But from what I see, it creates it in the current directory where I run the script.
Is there any way that running the script in the M module, from the C folder of the P project, generates a folder with the same name C but inside the new NP project?
Thanks:)
from the DXL manual: The name argument can be an absolute or relative name, and may include the path.. So, you might have a loop like
Project P = project ('/P')
Item i
for i in P do {
if (type i == 'Folder') {
string nName = name i
create ("/NP/" sName, "")
}
// recursively copy the content of the folder
}
Also, depending on your needs, you might want to have a look at clipCopy and clipPaste, which duplicates an entire hierarchy.

Groovy Script for PhpStorm Live Templates give suggested box?

So I have a little silly problem. I have a groovy script that reads all files in a folder and then manipulates the files in such a way to output the file names for the user to select the correct one in the live template variable. My problem is that the auto suggestion list only displays 1 item and not multiple items to select from in the IDE.
Here is the live template setup:
This is the output:
This is what I want (without using enum()):
This is the piece of code:
groovyScript("import static groovy.io.FileType.FILES;def curPath = _editor.getVirtualFile().getPath().split('/src/')[0];def dir = new File(curPath+'/src/partials');def files = [];dir.traverse(type: FILES, maxDepth: 1) { files.add(it.toString().replace('/src/partials/','').replace(curPath,'').replace('.html','')) }; return files;",methodParameters())
Please help... Since google searches does not yield any proper answers.
As of IntelliJ IDEA 2018.3, the groovyScript() feature does not support generating a list of suggestions. It can only be used to calculate a single suggestion which is then inserted into the editor.

Synchronize modification between SWT table and TextEditor

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);

SharePoint SPFile change extension on existing item possible?

I am at my wits end on this one. I have a user interface that creates and edits documents stored in a SharePoint document library. The trick part is I need to allow the user to update the document no problem just use SPFile.SaveBinary() right?
This definitely updates the contents of the file but somehow the old file name and the old extension persist, this is a problem. Deleting and re-adding the list item is not a solution either because the id of the item is being referenced in the url.
My question is how can I update the extension and filename metadata of the SPFile item?
So far all of my attempts using the object library have failed, i've tried updating the fields below none have been successful. It seems like there has to be an easier way to do this.
SPFile file = item.File;
file.Item[SPBuiltInFieldId.FileLeafRef] = resolvedFileName;
file.Item[SPBuiltInFieldId.FileRef] = "/File/" + resolvedFileName;
file.Item[SPBuiltInFieldId.BaseName] = System.IO.Path.GetFileNameWithoutExtension(resolvedFileName);
file.Item["Name"] = System.IO.Path.GetFileNameWithoutExtension(resolvedFileName);
file.SaveBinary(conduitFile);
file.Update();
[EDIT] - Here is my working solution.
SPFile file = item.File;
string resolvedFileName = item.ID.ToString() + "-" + conduitFileName;
item["Title"] = resolvedFileName;
file.SaveBinary(conduitFile);
file.MoveTo(item.ParentList.RootFolder.Url + "/" + resolvedFileName, true);
file.Item["Name"] = resolvedFileName;
file.Update();
After the file is saved to the library, use the MoveTo method and pass the modified file name in the newUrl parameter.
SPFile.MoveTo Method (String)
Quick & Easy: Rename Uploaded File Using SharePoint Object Model Via an Event Receiver
Another way that is simpler than using the MoveTo is to use the BaseName property of the SPListItem. You would set this by running
item["BaseName"] = resolvedFileName; //Whatever you want the new file name to be
item.Update();
This is easier than MoveTo because you don't have to worry about the folder hierarchy and you don't have to worry about the file extension.
For some reason the property is not listed on the MSDN documentation, but it seems to work well without a problem.

DataContext Doesn't Exist in Dynamic Data Project?

This is really annoying...and I know it is something extremely simple...
1. I create a new Dynamic Data project.
2. I add a LINQ-to-SQL class and drag and drop some tables onto the class.
3. I open the global.asax.vb and uncomment the line:
DefaultModel.RegisterContext(GetType(YourDataContext), New ContextConfiguration() With {.ScaffoldAllTables = True})
I remove YourDataContext and replace it with the DataContext from my LINQ-to-SQL class:
DefaultModel.RegisterContext(GetType(NorthwindDataContext), New ContextConfiguration() With {.ScaffoldAllTables = True})
I then try to debug/build/etc. and receive the following error:
Type 'NorthwindDataContext' is not defined
Why is it not defined? It seems like its not recognizing I created the DBML file.
This is a very strange issue and I am still not sure that I have entirely fixed the issue. But, here is what I think I have learned:
1. If you are creating a New Project in VS2010 you must place the LINQ-to-SQL DBML file in the root project directory.
2. If you are creating a new Web Site in VS2010 you must place the LINQ-to-SQL DBML file in a newly created App_Code directory.
3. If you place it in the wrong place, scrap the project and start over - it doesn't seem to work even if you move the files to the correct location or recreate them in the correct location.
Dave.
Does your project compile? I am guessing you are missing the namespace to your data context. Something like this:
model.RegisterContext(typeof(MyApp.MyNamespace.NorthwindDataContext),
new ContextConfiguration() { ScaffoldAllTables = true });