How to remove views from Windows-->Show View list? - swt

I have view which I am setting permanently on my perspective.
This view can not be closed and can not be opened from Windows --> show views
I struct to remove View from Windows --> view list.
How would I achieve this?
I tried your solution it is doing the things but it is also removing the view from perspective. Below are the steps I followed..
I have added the following view in plugin.XML
<view
allowMultiple="false"
category="org.view.ui.IDECategory"
class="org.view.ui.BannerInformationView"
id="org.view.ui.BannerInformationView"
name="BannerInfo"
restorable="true">
</view>
After this I have added this view in my Perspective
public void defineLayout( IPageLayout layout )
{
layout.setEditorAreaVisible( true );
layout.addStandaloneView( BANNER_INFO_VIEW_ID, false, IPageLayout.TOP, 0.03f, layout.getEditorArea() );
IViewLayout viewLayout = layout.getViewLayout( BANNER_INFO_VIEW_ID );
viewLayout.setMoveable( false );
}
Now I have added the activity to hide my view name from show view menu
<extension point="org.eclipse.ui.activities">
<activity
id="activity.ide"
name="ide">
</activity>
<activityPatternBinding
activityId="activity.ide"
isEqualityPattern="true"
pattern="org.view.ui.IDECategory.pluginid/org.view.ui.BannerInformationView">
</activityPatternBinding>
</extension>
Now my problem is, along with hiding the view entry from window -> show view, it is also hiding the view from my perspective.
I want to hide the only entry from show view so that user can not do anything with it, but it should be always visible in my perspective.

The view list is filtered by the activities list. So you can define an activity to suppress the view:
<extension point="org.eclipse.ui.activities">
<activity id="activity.id" name="Name">
</activity>
<activityPatternBinding
activityId="activity.id"
isEqualityPattern="true"
pattern="plugin.id/view.id">
</activityPatternBinding>
</extension>
Note: The pattern value is 'contributing plugin id / view id', a common mistake is leaving out the plugin id.

Related

Eclipse RCP: Conditionally enabling/disabling perspective in Perspectie Switcher

The Open Perspective View shows a list of perspectives to which a user can switch. My custom perspective is there, too. Can I have it not listed or greyed out, if a certain condition bis not met?
The second best alternative that comes to my mind is to have it listed, but the actual switch is not carried out, if b == false.
The best way for me was to use the extension point org.eclipse.ui.activities, as greg-449 suggested, and add a propertyTester. In order to hide perspective related UI elements and not every UI element from the same plugin, one can use isEqualityPattern="true".
<extension point="org.eclipse.ui.activities">
<activity
description="Remove some UI Elements"
id="com.my.plugin.ui.hideUI"
name="HideUI">
<enabledWhen>
<test
forcePluginActivation="false"
property="com.my.plugin.ui.PlanningPropertyTester">
</test>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="com.btc.edm.hidePlanning"
isEqualityPattern="true"
pattern="com.my.plugin.ui/id.of.the.perspective.to.hide">
</activityPatternBinding>
</extension>
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="com.my.plugin.ui.MyPropertyTester"
id="com.my.plugin.ui.propertyTester"
namespace="com.my.plugin.ui"
properties="MyPropertyTester"
type="java.lang.Object">
</propertyTester>
</extension>
It is important to have a fully qualified name for type.
The MyPropertyTester class extends org.eclipse.core.expressions.PropertyTester and overrides the test method.
public class MyPropertyTester extends PropertyTester {
#Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (goodWeather()) {
return true;
return false;
}
}

Hide/Remove a perspective provided by another plugin - eclipse

I noticed that I had dependencies on some of the Eclipse JDT and Plugin development features and due to this the RCP was showing some other perspective from the other ui plugins, which is unnecessary entries in my product of Preference Perspective.
I tried with the below snippet, but still the perspective is showing in the preference perspective.
Call the removeUnWantedPerspectives() (attached below) method from postWindowCreate() method of your RCP’s WorkbenchWindowAdvisor extension class –
private String[] IGNORE_PERSPECTIVES = new String[] {
"com.abc.xyz.ui.calibrationPerspective" };
/**
* Removes the unwanted perspectives from your RCP application
*/
private void removeUnWantedPerspectives() {
IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry();
IPerspectiveDescriptor[] perspectiveDescriptors = perspectiveRegistry.getPerspectives();
List ignoredPerspectives = Arrays.asList(GenericConstants.IGNORE_PERSPECTIVES);
List removePerspectiveDesc = new ArrayList();
// Add the perspective descriptors with the matching perspective ids to the list
for (IPerspectiveDescriptor perspectiveDescriptor : perspectiveDescriptors) {
if(ignoredPerspectives.contains(perspectiveDescriptor.getId())) {
removePerspectiveDesc.add(perspectiveDescriptor);
}
}
// If the list is non-empty then remove all such perspectives from the IExtensionChangeHandler
if(perspectiveRegistry instanceof IExtensionChangeHandler && !removePerspectiveDesc.isEmpty()) {
IExtensionChangeHandler extChgHandler = (IExtensionChangeHandler) perspectiveRegistry;
extChgHandler.removeExtension(null, removePerspectiveDesc.toArray());
}
}
I tried with activities extension also, but this dosen't works for me
<extension
id="com.abc.xyz.pmse.application.activities.hideperspective"
name="Hide Perspectives"
point="org.eclipse.ui.activities">
<activityPatternBinding
activityId="com.abc.xyz.pmse.application.activities.hideperspective"
pattern=".*/com.abc.xyz.ui.calibrationperspective">
</activityPatternBinding>
<activityPatternBinding
activityId="com.abc.xyz.pmse.application.activities.hideperspective"
pattern=".*/com.abc.xyz.ui.varianthandlingperspective">
</activityPatternBinding>
</extension>
My working activities extension snippet looks like
<extension
point="org.eclipse.ui.activities">
<activity
id="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
name="Hide UnwantedPerspective">
<enabledWhen>
<equals
value="false">
</equals>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
isEqualityPattern="true"
pattern="com.abc.xyz.ui.parameter.impl/com.abc.xyz.ui.calibrationperspective">
</activityPatternBinding>
<activityPatternBinding
activityId="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
isEqualityPattern="true"
pattern="com.abc.xyz.ui.dcmmapping/com.abc.xyz.ui.varianthandlingperspective">
</activityPatternBinding>
<activityPatternBinding
activityId="com.abc.xyz.svn.ui.activity.hideunwantedperspective"
isEqualityPattern="true"
pattern="com.abc.xyz.ui.dcmmapping/com.abc.xyz.ui.varianthandlingperspectivenew">
</activityPatternBinding>
</extension>

Parent Acitivity's status not kept when backing from child activity

In AndroidManifext.xml, I have :
<activity
android:name=".mypackage.ChildActivity"
android:label="Child"
android:parentActivityName=".mypackage.ParentActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".view.activities.ParentActivity" />
</activity>
Inside ParentActivity, I have a few fragements, A, B, C. At fragment C, I launch ChildActivity when clicking a button. When backing to ParentActivity, I am not landing on Fragment C, but Fragment A. It appears that ParentActivity is relaunched or initialized again.
In ChildActivity, I have:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
As a comparison, I also tried to replace ChildActivity with a Fragment D and backing from fragment D correctly lands on fragment C.
Where did I miss for the ChildActivity implementation?
Edited:
Just noticed that when clicking "Back" button on device, it properly backs to Fragment C of ParentActivity, but if hitting the "<" button at the left top corner in Child Activity, that's where issue arises.
Thanks in advance!
Shawn
Remove the mentioning parent from your childActivity. Like below. Because android already maintains the stack of navigations
<activity
android:name=".mypackage.ChildActivity"
android:label="Child"
android:parentActivityName=".mypackage.ParentActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
</activity>

Eclipse RCP Can't Contribute to Main Toolbar

My RCP app has the coolbar visible by setting configurer.setShowCoolBar(true) in WorkbenchWindowAdvisor#preWindowOpen. But when I contribute a toolbar to the main toolbar, it never shows up. Here's my contribution code:
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="true"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="toolbar.perspectivesDynamic">
<dynamic
class="my.package.PerspectiveSwitcherToolbar"
id="perspectiveSwitcherToolbar">
</dynamic>
</toolbar>
</menuContribution>
</extension>
And the ContributionItem class:
public class PerspectiveSwitcherToolbar extends ContributionItem {
...
#Override
public void fill(final ToolBar parent, int index) {
//Does not get called
}
#Override
public void fill(CoolBar parent, int index) {
//Does not get called
}
...
}
I'm using this code for adding a custom perspective switcher. It's rather old, but I see examples everywhere on the Internet adding a toolbar like this to the main toolbar, so I'm missing something elsewher, I assume
I think that is bug 392457: <toolbar><dynamic></toolbar> doesn't work at the moment. You can work around it by using a <control> and managing the contents yourself.

How to lay out a perspective to make the left region with two parts: top and bottom?

Tried both Programmatic and Declarative way but failed, and I just wanna make the left region lay out like below. Any hints?
Create a folder for the left column and then put two more folders in the column:
IFolderLayout leftOuter = layout.createFolder("left.outer", IPageLayout.LEFT, 0.23f, IPageLayout.ID_EDITOR_AREA);
IFolderLayout leftTop = layout.createFolder("left.top", IPageLayout.TOP, 0.5f, "left.outer");
// TODO add views and placeholders to leftTop
IFolderLayout leftBottom = layout.createFolder("left.bottom", IPageLayout.BOTTOM, 0.5f, "left.outer");
// TODO add views and placeholders to leftBotton
Finally I've found a declarative way to handle this
(which is inspired by the layout of Eclipse internal CVS Repositories Exploring perspective and decompiled its source code)
plugin.xml
<!-- ************** Perspective Extensions START **************** -->
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="$YOUR_PERSPECTIVE_ID$">
<view
closeable="false"
id="$BOTTOM_VIEW_ID$"
moveable="false"
ratio="0.6"
relationship="bottom"
relative="$TOP_VIEW_ID$"
showTitle="true"
standalone="true">
</view>
</perspectiveExtension>
</extension>