Display views in custom eclipse perspective - java

I have a perspective which i have made, and a bunch of views i would like to be able to display on this perspective. If i go Window -> Show View -> Other and then select my view it works fine. However i would like to show a view by default upon opening the perspective and place it where the project explorer usually would be.
But nothing i do seems to change anything and i cannot find any reason why.
I have been using this code to try to change the location of this view but it doesn't even open the view by default. can someone point me in the right direction on how to open a view by default and place it where the project explorer usually would be?
public class PerspectiveFactory1 implements IPerspectiveFactory {
public void createInitialLayout(IPageLayout layout) {
layout.addView("VIEW_ID_HERE", IPageLayout.LEFT,
IPageLayout.RATIO_MAX, IPageLayout.ID_PROJECT_EXPLORER);
}
}
Thanks in advance
Here is my plugin.xml
<plugin>
<extension
point="org.eclipse.ui.perspectives">
<perspective
class="packageName.PerspectiveFactory1"
fixed="true"
id="PerspectiveID"
name="Software Application">
</perspective>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="PerspectiveID">
<view
class="packageName.ShowApplications"
icon="icons/sample.gif"
id="packageName.ShowApplications"
minimized="false"
moveable="false"
name="listApps"
ratio="0.5"
relationship="left"
visible="true">
</view>

Since you don't have the project explorer in that perspective you can't use its id in the reference id parameter to addView. Instead use the editor area id which is always allowed:
layout.addView("view id", IPageLayout.LEFT,
0.3f, layout.getEditorArea());
You may also have to Reset the perspective if it has been open before to get the new layout picked up (Window > Perspective > Reset Perspective).
The view must be defined using the org.eclipse.ui.views extension point.
You can also use the org.eclipse.ui.perspectiveExtensions to define the position of a view in the perspective instead of the perspective factory - but this still requires the view to be defined using org.eclipse.ui.views.

Related

Chip programmatically generated not responding to click in ChipGroup

I've made a chipgroup and I want to dynamically generate in java its content, populating it with filter chips made from strings. I've made the Chipgroup but trying to add chips I notice that, no matter what I do, the chips are not responding to clicks. I also tried to make a single chip in the design editor and moving it in the same chipgroup, the results is that the design editor created chip is working as intended (checking and unchecking it), the generated ones are static (in the same group).
the code I use for the single working one:
<com.google.android.material.chip.ChipGroup
android:id="#+id/iChipGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:chipSpacing="8dp"
app:singleSelection="true" >
<com.google.android.material.chip.Chip
android:id="#+id/chip2"
style="#style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="cwae" />
</com.google.android.material.chip.ChipGroup>
the way I create the dynamic ones
Chip chip = new Chip(iChipGroup.getContext());
ChipDrawable chipDrawable = ChipDrawable.createFromAttributes(getContext(), null, 0, R.style.Widget_MaterialComponents_Chip_Filter);
chip.setChipDrawable(chipDrawable);
chip.setText(myText);
iChipGroup.addView(chip);
I've also tried to set an OnCheckedhangeListener both on the single chips and ChipGroup, got nothing.
If it helps, my hierarchy is (inside a fragment):
frameLayout
-scrollView
--LinearLayout
---chipGroup
----chip...
managed to make the chip respond by changing the way I made them this way
LayoutInflater layoutInflater = getLayoutInflater();
Chip chip = (Chip)layoutInflater.inflate(R.layout.my_filter_chip,ingredientsChipGroup, false);

RCP visiblewhen programmatically (Java)

I have a command into the plugin.xml which will add a new menu button. This button should not be visible all the time, hence I would like to check a complex condition from Java code to decide when it have to be visible.
I know that there is a visiblewhen and a hidewhen possibility, but I don't know how can let a Java class/method to make the decision.
For this check the enabled state of the command is used, which is determined by the return value of IHandler.isEnabled().
In the plugin.xml the contribution of the command to the menu has to have the visibleWhen element and checkEnabled="true". In Eclipse you can right click the command contribution and add visible when, in the plugin.xml it looks like this:
<command
commandId="...">
<visibleWhen
checkEnabled="true">
</visibleWhen>
</command>
To enable/disable the command you have to implement the isEnabled() method from org.eclipse.core.commands.IHandler (or override from AbstractHandler) in your command handler and return false, if the menu entry should be hidden.

Can I use org.eclipse.core.variables... in defining attributes of other extensions

I'm creating an RCP 3.7 editor by using org.eclipse.ui.editors extension point. What I need is to dynamically define icon path based on some conditions during editor startup.
(EDIT: The editor is actually just restored after startup, but it's not selected as active yet, so you can see only tab with title and icon)
I tried to work with getImageDescriptor() method in class implementing IEditorInput, which doesn't seem to be used. The only way that has some effect on the icon is changing the icon path in definition of editor extension.
Therefore I started to play with org.eclipse.core.variables.valueVariables and org.eclipse.core.variables.dynamicVariables for use in icon attribute (showing valueVariables just for easy example):
<extension point="org.eclipse.ui.editors">
<editor name="%Editor_TITLE"
extensions="xml"
icon="${FOO}"
class="org.example.ExampleEditor"
id="org.example.ExampleEditor">
</editor>
</extension>
<extension point="org.eclipse.core.variables.valueVariables">
<variable name="FOO"
initialValue="images/obj16/editor.png">
</variable>
</extension>
However, that doesn't work either. Is there some way to use dynamically defined variable values (based on current condition) that could change the path of icon? ...or I'll be greatfull even for a workaround suggestion, that will lead to successful changing of the icon during startup (like making the ImageDescriptor work no startup).
Variables only work in places where they are explicitly support in the code. If the documentation for an extension point does not say they are supported then they won't work.
You get use the image descriptor from the editor input to set the editor title image by doing something like the following in your editor's init method:
public void init(IEditorSite site, IEditorInput input)
throws PartInitException
{
... other code
ImageDescriptor desc = input.getImageDescriptor();
Image image = desc.createImage();
setTitleImage(image);
... other code
}

Customizing the built in WorkbenchAction

I just started working on a project using RCP. And in its "about" section, it uses
the built in WorkbenchAction:
IWorkbenchAction actionAbout = ActionFactory.ABOUT.create(window);
actionAbout.setText(Messages.ABOUT);
itemAbout = new ActionContributionItem(actionAbout);
However, I need to add a tab in that popup and I'm not finding any way to customize
it. Is this something possible or should look for another way to do things?
Use the org.eclipse.ui.installationPages extension point to add a tab to the Installation Details tabs.
<extension point="org.eclipse.ui.installationPages">
<page
name="XYZ Info"
class="package.XYZInstallInfoPage"
id="plugin.xyz>
</page>
</extension>
Your class must extends org.eclipse.ui.about.InstallationPage
For more details see the help

Eclipse plugin: Custom icon for a Marker

I want to specify a custom icon for a marker. Sadly, the icon that I chose is not displayed.
Here's the relevant parts of the plugin.xml file (the project id "x"):
<extension
id="xmlProblem"
name="XML Problem"
point="org.eclipse.core.resources.markers">
<super type="org.eclipse.core.resources.problemmarker"/>
<persistent
value="true">
</persistent>
</extension>
<extension
point="org.eclipse.ui.ide.markerImageProviders">
<imageprovider
markertype="x.xmlProblem"
icon="icons/marker.png"
id="xmlProblemImageProvider">
</imageprovider>
</extension>
I also tried specifying a class (implementing IMarkerImageProvider) instead of an icon, but that getImagePath() method of the class does not get called.
Any thoughts on how to make custom marker icons work?
Desperately, yours.
-Itay
Update
VonC's solution is pretty much correct, except that you must not specify org.eclipse.core.resources.problemmarker as a supertype of your marker. It worked only when I used org.eclipse.core.resources.textmarker as the only supertype.
See bug 260909 "markerImageProviders extension point does not work" (found after reading this thread)
Tod Creasey 2009-01-21 07:32:38 EST
We have never had the push to make this API because it has some inflexibility that made it generally not consumable - it was written early on to enable the first marker views for the 3 severities we use and as a result was not used by the markerSupport as it was not API.
It is confusing that we have an internal extension point (we don't generally do
that) but removing it would likely break someone without warning.
[EDIT by Itay]
Following on Vonc's pointers, I eventually managed to make this thing work.
Here are the relevant fragments from my plugin.xml (assuming the plugin name is a.b.c)
<extension point="org.eclipse.core.resources.markers"
id="myMarker">
<super type="org.eclipse.core.resources.textmarker"/>
<persistent value="true"/>
</extension>
<extension point="org.eclipse.ui.editors.annotationTypes">
<type
super="org.eclipse.ui.workbench.texteditor.warning"
markerType="a.b.c.myMarker"
name="a.b.c.myAnnotation"
markerSeverity="1"/>
</extension>
<extension point="org.eclipse.ui.editors.markerAnnotationSpecification">
<specification
annotationType="a.b.c.myAnnotation"
icon="icons/marker.png"
verticalRulerPreferenceKey="myMarkerIndicationInVerticalRuler"
verticalRulerPreferenceValue="true"/>
</extension>
Pitfalls
The super type of the marker must be set to org.eclipse.core.resources.textmarker. Any other value will prevent your custom icon from being used.
When you create a marker in your code make sure its severity matches the severity value specified in the markerSeverity attribute at the org.eclipse.ui.editors.annotationTypes extension point. 1 means warning, etc.
Make sure the icons folder is specified in your build.properties file (or the "build" tab at the plugin editor)
The declaration above will only specify a custom icon. If you want to customize other attributes (color of indication at the overview ruler, etc.) follow the sample from here on which this solution is based.

Categories