Adding title to window border for Eclipse RCP detached view - eclipse

I am working on an Eclipse RCP project which has detachable views. I would like to be able to put some text on the window border which surrounds the view once it is detached. Does anyone have any experience with this? Development environment is Eclipse 3.4 on Windows.
THANKS.

I am not sure it is possible through the conventional update triggering a updateTitle():
If you take a look at the code of org.eclipse.ui.internal.DetachedWindow, you will see a disturbing method updateTitle():
private void updateTitle() {
if (activePart != null) {
// Uncomment to set the shell title to match the title of the active part
// String text = activePart.getTitle();
//
// if (!text.equals(s.getText())) {
// s.setText(text);
// }
}
}
All commented!

You cannot. The detached one is a tool window rather than a main window, so it isn't good to have a title on it

Related

net Maui text Editor text cursor issue

I am developing a simple app using Maui .net but facing some challenge perhaps you can give some advice.
I have a multiline text field of type "Editor" and I have one button. The onclicked event of the button should insert the button label text into the Editor mentioned above (very simple task). Now, the issue is when I use the myEditor.Text.Insert(myEditor.Text.Length, myButton.Text) the inserted text inserts fine, but the blinking text cursor moves to the far left of the Editor field, instead of staying at the far right.
I tried working around this issue but manually moving the text cursor using the myEditor.CursorPosition but the problem is what if the user decided to manually change text cursor location? then pressing the button would insert at the myEditor.Text.Length index, thus ignoring the user's intent to insert the text at a specified index.
I wasn't able to find a method that triggers an event when the text cursor moves inside a text Editor in Maui (so that I can handle it in my own way)
Note: When typing using the Android keyboard, there are no issues at all. but only if inserting text programmatically using .Insert(index,string)
Thanks.
You can try to use the handler to get the cursor position when you insert the text into the Editor.
Declare the control on the android platform:
#if ANDROID
AppCompatEditText nativeEditText;
#endif
Create the method which can get the control's cursor position for android:
void GetCursorPosition ()
{
Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
{
#if ANDROID
nativeEditText = handler.PlatformView;
});
}
Add code in the button's clicked event:
int cursorPosition = 0;
private void Button_Clicked(object sender, EventArgs e)
{
cursorPosition = nativeEditText.SelectionStart; //get the cursor position if user chooses a position by tapping the editor
string insertText = button.Text;
if (nativeEditText.IsFocused == true)
{
editor.Text = editor.Text.Insert(cursorPosition, insertText);
editor.CursorPosition = cursorPosition + insertText.Length;
//set the position at the end of text inserted
}
else
{
editor.Text = editor.Text.Insert(editor.Text.Length, insertText);
}
}
Updating Visual Studio to version 17.3.0 Preview 5.0 fixed the issue without further tweaks. This fix came in parallel with the time I was facing this issue and looking for a fix 😅

How to have custom script icons other than using "Assets/Gizmos" in Unity3D

I know this was asked a lot of times probably .. but it is very often answered wrong.
What I want is:
Use a custom icon for specific components/scripts in the Inspector (e.g. Figure 2 and Figure 3) and the ProjectView (e.g. Figure 1)
What I do so far:
For each component/class that shall have the icon I have an accroding Icon file in the folder
Assets/Gizmos/<Path>/<To>/<Namespace>/<ClassName> icon
and in the Import Settigns set TextureType to Editor GUI and Legacy GUI
This is working fine .. and until now the only way how I could achieve that (having in mind the below section What I definitely do NOT want).
But
However, I wondered if there is really no better way having to have a unique Icon file for each script. This makes the project/UnityPackage unnecessarily huge. Also if I rename a class I always have to rename the according icon file as well ... This imply doesn't feel right!
Most Unity build-in Behaviours and Components have a unique icon. But also external Packages coming from the new PackageManager have built-in icons and sometimes a Gizmos folder but it is not following the above naming rule ... so apparently the icon is configured somehow else for them.
Therefore my questions:
Is there any better way to have those icons for scripts/components?
Preferably scripted and reusing ONE single icon file instead of having the same icon in multiple differently named files.
And/or also Where/How are those icons defined for the scripts coming from the PackageManager?
!NOTE! What I definitely do NOT want:
Show the Icon also in the SceneView for all GameObjects having those components attached (e.g. Figure 4). This is caused by either selecting the icon for this script via the Inspector as in Figure 5 (as allways suggested e.g. in this post or here and even by Unity - Assign Icons ) or using OnDrawGizmos or DrawGizmo. This is not happening using the approach I use currently with the Gizmos folder!
Update
Because this was suggested in this answer: I also know that I could do that and turn them off via the Gizmos settings of the SceneView. But imagine I have like 25 different modules and various different icons each. I don't want to have to disable their Gizmos in the SceneView settings one by one on a per project basis! Even the provided script seems like a vast hackaround. Reflection would be the very last resort I would ever take. Also I'ld prefer to not even have those icons appear as possible Gizmos at all instead of disabling them all.
You can set the icon with figure 5 and then turn the gizmos for that icon off from the gizmos drop down.
Edit: Injunction with the step above you could try this script derived from here it uses reflection to find the class responsible for turning off the the gizmos and icons. This would execute any time your scripts recompiled to keep those icons off or if you added any new icons to the autohide icon file. Note: scriptClass will be an empty string for built in components eg.Camera, AudoSource
using UnityEditor;
using System;
using System.Reflection;
public class DisableAllGizmos
{
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
var Annotation = Type.GetType("UnityEditor.Annotation, UnityEditor");
var ClassId = Annotation.GetField("classID");
var ScriptClass = Annotation.GetField("scriptClass");
var Flags = Annotation.GetField("flags");
var IconEnabled = Annotation.GetField("iconEnabled");
Type AnnotationUtility = Type.GetType("UnityEditor.AnnotationUtility, UnityEditor");
var GetAnnotations = AnnotationUtility.GetMethod("GetAnnotations", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
var SetIconEnabled = AnnotationUtility.GetMethod("SetIconEnabled", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
Array annotations = (Array)GetAnnotations.Invoke(null, null);
foreach (var a in annotations)
{
int classId = (int)ClassId.GetValue(a);
string scriptClass = (string)ScriptClass.GetValue(a);
int flags = (int)Flags.GetValue(a);
int iconEnabled = (int)IconEnabled.GetValue(a);
// this is done to ignore any built in types
if (string.IsNullOrEmpty(scriptClass))
{
continue;
}
// load a json or text file with class names
const int HasIcon = 1;
bool hasIconFlag = (flags & HasIcon) == HasIcon;
// Added for refrence
//const int HasGizmo = 2;
//bool hasGizmoFlag = (flags & HasGizmo) == HasGizmo;
if (/*Compare class names in file to scriptClass == true*/)
{
if (hasIconFlag && (iconEnabled != 0))
{
UnityEngine.Debug.LogWarning(string.Format("Script:'{0}' is not ment to show its icon in the scene view and will auto hide now. " +
"Icon auto hide is checked on script recompile, if you'd like to change this please remove it from the config",scriptClass));
SetIconEnabled.Invoke(null, new object[] { classId, scriptClass, 0 });
}
}
}
}
}
Shown in the inspector with a gizmo
Hide Icon from gizmos dropdown
Icon still appears in the inspector and in the project view but not in the scene
So I did a bit more research about built in types as well as packages coming from the package manager and the asset store. Anything that is external (packagemanager or assetstore) if it has a custom icon for the script and inspector it will Always have a gizmo in the scene view. As it has its icon set using your figure 5 example, as seen in the screenshots with the debug inspector.
Also if you want to set the icon with a script or hide it ,currently reflection is your only option as these APIs are not publicly accessible.
My Script showing the debug inspector for its script
PixelPerfect package script from the packagemanager in the debug inspector
PixelPerfect Icon showing in the scene
I was hoping to add this as a comment to your original question but not enough rep yet.

MPart is not user after switch perspective

I have an issue related to switching perspectives in E4. The two perspectives shares the same MPart. After switching to a new perspective the new MPart will be used. After swithing back to the original perspective the second MPart will still be used instead of the first one.
In the image you can find the application structure and both of the Perspectives has Outline screen on it.
When opening perspective one, the Outline works for that perspective. Then if we switch to perspective two (that has different other screen) the second Outline will be activated and works correct. When switching back to the first perspective the second Outline will be still active and the first Outline will not respond to any requests.
After switching to perspective I active all the MPart back with:
List<MPart> part = service.findElements(perspective, null, MPart.class, null);
List<MPartStack> mainPartStack = service.findElements(perspective, "partstack.shared", MPartStack.class, null);
if (!mainPartStack.isEmpty()) {
for (int i = part.size() - 1; i >= 0; i--) {
List<MPart> children = service.findElements(mainPartStack.get(0), part.get(i).getElementId(), MPart.class,
null);
if (!children.contains(part.get(i))) {
this.partService.activate(part.get(i));
}
}
}
How can I activate the first Outline back so that it will respond to new request from the first perspective?
Created a shared Outline part and use a placeholder to reuse the Outline. With this solution I changed the perspective switch implementation. So that if a user go back to the first perspective that the data of the outline is the same when he was switching to the second.

How to put image on JPanel?

I know this has probably been ask one billion times, but I am still finding it difficult in getting a straight forward answer.
Where do you put the code under? Can you just add it through the GUI builder-if so how? Or do you have to 'manually' add it in the code? If so do you put it under public class or just class? How to you write it?
Though I would personally prefer if there was a way to add the photo through the GUI builder.
Also, if I added an imagine to a JLabel, would it be possible for me to set it as a background so all the other JLabels or Buttons etc in the GUI is overlapping the picture?
Netbeans version 6.9.1
In Netbeans it is a little bit difficult to do this but still it could be done (not as easy as VS). You just have to follow the following steps:
Create the new JPanel object using the wizard
Go to the Source mode and paste the following text
-
public NewJPanel() { //this is the contsructor , so change the name apropriately
try {
image = ImageIO.read(new File("c:\\1.png")); //path to your image
} catch (IOException ex) {
}
initComponents();
}
private BufferedImage image;
#Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, null); //image drawing properties
}
Import all apropriate libs
Save the NewJPanel file.
Now go to your JFrame and drag and drop a Panel Object from the Swing Container list
Right click on the new jPanel object and select Customize Code from the menu
In the Code Customizer box select Custom creation and enter the following code. see image below
jPanel1 = new NewJPanel();
By doing this you replace the standard JPanel object with the one you created in the first steps
Click ok and then run your JFrame. You should see the image inside the JPanel now
PS: My Netbeans version is 7.2.1

Drawing into an Eclipse editor

I am trying to draw some shapes (boxed ans arrows) into, i.e., "over" the text in an eclipse editor. To get started, I wrote the following code:
IWorkbenchPage activePage = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
final Shell shell2 = activePage.getActiveEditor().getSite().getShell();
shell2.addPaintListener(new PaintListener(){
public void paintControl(PaintEvent e){
Rectangle clientArea = shell2.getClientArea();
e.gc.drawLine(0,0,clientArea.width,clientArea.height);
}
});
The problem with this code is twofold: (1) The line is drawn not across the editor but across the entire workbench, i.e., Eclipse window, and (2) the line is drawn behind (!) all other controls like toolbars and editors. This causes the line to be almost invisible: it only shows at some pixels between other controls.
How can I draw a line across a control like a text editor in Eclipse?
The problem that you have is that you are getting the Shell, not the actual component for the editor. The Shell is the whole window where Eclipse is being shown.
I think the only solution is to create your own Editor implementation, and then in the createPartControl() method you can create a text area and then add the paint listener to it.
You can get started with:
http://www.realsolve.co.uk/site/tech/jface-text.php
And then, looking at the source code of AbstractTextEditor, you can find the "real" SWT component that you want to draw to. You would need to override the method that creates the UI components, copy the original code and add your custom painting.
I'm not sure if it works, but you need to extend the TextEditor:
public class MyEditor extends TextEditor {
protected StyledText createTextWidget(Composite parent, int styles) {
StyledText widget = super.createTextWidget( parent, styles );
widget.addPaintListener( <yourPaintlistener> );
return widget;
}
}
That should at least get you the basic text-drawing control of the editor. Still, it's a PITA to work with these classes, as it is very internal stuff from eclipse, and neither documented nor really extensible.
Good luck with that :)