How to remove Eclipse Move from context menu and refactor main menu - eclipse-plugin

I want to remove move command for specific resource type. To achieve it, I thought to using org.eclipse.ui.activities
I tried below configuration, but it didn't work.
<extension
point="org.eclipse.ui.activities">
<activity
id="refactormovehiding.id"
name="refactormovehiding">
<enabledWhen>
<not>
<instanceof
value="com.shashwat.resource.PResource">
</instanceof>
</not>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="refactormovehiding.id"
pattern=".*/org.eclipse.jdt.ui.actions.Move">
</activityPatternBinding>
</extension>
I even used different pattern thinking pattern which I am providing is incorrect
<extension
point="org.eclipse.ui.activities">
<activity
id="refactormovehiding.id"
name="refactormovehiding">
<enabledWhen>
<not>
<instanceof
value="com.shashwat.resource.PResource">
</instanceof>
</not>
</enabledWhen>
</activity>
<activityPatternBinding
activityId="refactormovehiding.id"
pattern=".*/org.eclipse.ltk.ui.refactoring.commands.moveResources">
</activityPatternBinding>
</extension>
I even tried without enabledWhen configuration, but no luck.

Related

Project explorer Delete Action not working as expected

Eclipse Default Delete action on the project explorer (context menu, key binding) not working as expected.
In Project explorer I do have 2 different files let's assume ".pc" and ".tc" files.
I want to restrict the user from deleting the ".tc" files from project explorer for that I have written custom handlers to restrict it. Actions are configured as below.
<handler
class="MyTCFileDeleteHandler"
commandId="org.eclipse.ui.edit.delete">
<activeWhen>
<with
variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
<test
property="org.eclipse.core.resources.extension"
value="tc">
</test>
</iterate>
</with>
</activeWhen>
</handler>
<handler
class="MyTCFileDeleteHandler"
commandId="org.eclipse.ltk.ui.refactoring.commands.deleteResource">
<activeWhen>
<with variable="selection">
<iterate
ifEmpty="false">
<instanceof
value="org.eclipse.core.resources.IResource">
</instanceof>
<test
property="org.eclipse.core.resources.extension"
value="tc">
</test>
</iterate>
</with>
</activeWhen>
</handler>
But due to this DeleleParticepent wrote are not getting calls for ".pc" file deletion.
Also, this misbehaves for shortcuts, context menus differently.
What I want to achieve, I should restrict the deleting of some files according to extension and some not, and my participant should call if the file is deleting. And this should work for the context menu, shortcut.

Why is this Eclipse RCP plugin missing a view?

I am experimenting with the way an Eclipse RCP application is dealing with its plugins. In Eclipse IDE I created an Eclipse RCP 3.x project with a view that generated all the necessary files and worked just fine.
Assuming that I can transform this application into one that only holds an empty perspective just by removing the respective parts of the plugin.xml file, I commented out all the lines that deal with the view like so:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="application"
point="org.eclipse.core.runtime.applications">
<application>
<run
class="pluginwithview.Application">
</run>
</application>
</extension>
<extension
point="org.eclipse.ui.perspectives">
<perspective
name="Perspective"
class="pluginwithview.Perspective"
id="PluginWithView.perspective">
</perspective>
</extension>
<!--
even without these lines
there's an Exception thrown saying:
"Could not create the view: PluginWithView.view
-->
<!-- <extension
point="org.eclipse.ui.views">
<view
name="View"
inject="true"
class="pluginwithview.View"
id="PluginWithView.view">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="*">
<view
standalone="true"
minimized="false"
relative="org.eclipse.ui.editorss"
relationship="left"
id="PluginWithView.view">
</view>
</perspectiveExtension>
</extension> -->
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:org.eclipse.ui.main.menu">
<menu
label="File">
<command
commandId="org.eclipse.ui.file.exit"
label="Exit">
</command>
</menu>
</menuContribution>
</extension>
</plugin>
But instead of displaying an empty perspective, the app now looks like so:
What must I do to not have the application search for the view ? Is there a config file that I am missing ? (I know there a few reasons to not have a view , but right now I am mainly interested in the inner workings of an Eclipse RCP application)
Perspectives remember the views they contained. If you change the perspective definition you will have to do a perspective reset ('Window > Perspective > Reset Perspective') to get it to read the updated definition.
For testing you can also specify the -clean and -clearPersistedState options in the 'Program Arguments' section of the RCP Run Configuration to discard all saved information.

How to make Log4j2 configurable by environment using Spring Boot 1.3.6.RELEASE

I would like to change some properties from the log4j2.xml file depending on the my application.properties, for example define some properties and then substitute in the log4j2 those properties that are parameters.
I ran different approaches but I still did not get the right thing. I would like to have different configs depending on the environment (DEV, QA or PROD). How to accomplish this?
I'm trying to have this in my properties
#Place holders for log4j2.xml file
log.file.path=/opt/tomcat/logs
log.file.name=dummydummy
log.file.size=100 MB
log.level=DEBUG
My log4j2 below.
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="PID">????</Property>
<property name="name">my-log</property>
</Properties>
<Appenders>
<RollingFile name="file" fileName="${log.file.path}${log.file}.log"
filePattern="${log.file.path}${log.file}-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout
pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${sys:PID} --- [%t] %c{1}(%M:%L) : %m%n%wEx" />
<Policies>
<TimeBasedTriggeringPolicy /><!-- Rotated everyday -->
<SizeBasedTriggeringPolicy size="${log.file.size}" /> <!-- Or every 100 MB -->
</Policies>
</RollingFile>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout
pattern="%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%t]}{faint} %clr{%c{1}(%M:%L)}{cyan} %clr{:}{faint} %m%n%wEx" />
</Console>
</Appenders>
<Loggers>
<Logger name="org.hibernate.validator.internal.util.Version"
level="warn" />
<Logger name="org.apache.coyote.http11.Http11NioProtocol" level="warn" />
<Logger name="org.apache.tomcat.util.net.NioSelectorPool" level="warn" />
<Logger name="org.apache.catalina.startup.DigesterFactory" level="error" />
<Logger name="org.springframework.web" level="error" />
<Root level="${log.level}">
<AppenderRef ref="Console" />
<AppenderRef ref="file" />
</Root>
</Loggers>
</Configuration>
The properties lookup element allows to refer properties from an external properties file in the log4j configuration.
For your example it should be something like this:
A file env.properties contains the following properties:
log.file.path=/opt/tomcat/logs
log.file.name=dummydummy
log.file.size=100 MB
log.level=DEBUG
The properties lookup should be defined as properties of the log4j2.xml:
<Configuration>
<Properties>
<property name="log.file.path">${bundle:env:log.file.path}</property>
<property name="log.file.name">${bundle:env:log.file.name}</property>
<property name="log.file.size">${bundle:env:log.file.size}</property>
<property name="log.level">${bundle:env:log.level}</property>
</Properties>
Now the properties may be referred in appenders with ${property_name} notation. Each property reference will be interpolated with the real value from the env.properties.
You can find another example of properties lookup here.
As of Log4j 2.13.0 Log4j 2 now provides a Spring Lookup as part of its Spring Cloud Config support. It will allow you to reference properties defined in your application.properties or application.yml file of your Spring Boot application in the log4j2.xml.
Since log4j 2.14.0, you can now use Spring Boot environment variables without Spring Cloud and without doing direct reference to the properties file. You'll need at least Spring Boot 2.0.3
<property name="applicationName">${spring:spring.application.name}</property>
Documentation: https://logging.apache.org/log4j/2.x/log4j-spring-boot/index.html
Maven repository: https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-spring-boot
Ensure that log4j2 starter is added in the classpath and then remove logging related properties in application.properties then spring will load your log4j2.xml from resources folder.
This way you can have full control over logging. If you want to substitute values then refer this link
Note:: If you have actuator in your project then remove spring boot logger starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
Workaround in case you need just different property values in log4j2.xml config for different spring profiles (dev, test, prod, etc.).
You could access spring profile files like: ${bundle:application-${sys:spring.profiles.active}:log.file.name}
application-dev.properties file:
log.file.name=dev_log
application-prod.properties file:
log.file.name=app_name
log4j2.xml config:
<Configuration>
<Properties>
<Property name="file_name">${bundle:application-${sys:spring.profiles.active}:log.file.name}</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile"
fileName="/logs/${file_name}.log"
...
NOTE: You have to add log.file.name property to each spring profile, log4j2 sees it just as separate text files and will not resolve default values from application.properties file and etc.

Showing command on toolbar based on perspective

I want to show a command on the toolbar based on the perspective. I have used core expressions to achieve this as below.
<extension point="org.eclipse.core.expressions.definitions">
<definition id="onValidationPerspective">
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="com.sample.perspective1"/>
</with>
</definition>
</extension>
and I have used this in the command tag as below.
<command
commandId="com.sample.run.root"
icon="icons/run_exc.gif"
label="Reset Card"
style="pulldown">
<visibleWhen checkEnabled="false">
<reference
definitionId="onValidationPerspective">
</reference>
</visibleWhen>
</command>
The above code is working fine.
But I want to extend this for mutiple perspectives, i.e. I want to show the commands on the toolbar in 2 perspectives namely com.sample.perspective1 and com.sample.perspective2.
How can I achieve this using core expressions?
You can use the OR operation element:
<definition id="onValidationPerspective">
<or>
<with ...
<with ...
</or>
</definition>
<definition id="onValidationPerspective">
<with variable="activeWorkbenchWindow.activePerspective">
<or>
<equals value="com.sample.perspective1"/>
<equals value="com.sample.perspective2"/>
</or>
</with>
</definition>

delete popup working fine over project explorer view but not working over navigator view

I am trying to hide 'delete' popup-menu for some files. I used following plugin.xml entry.
<extension point="org.eclipse.ui.activities">
<activity id="hidedeletepopupmenuID" name="hidedeletepopupmenu">
<enabledWhen>
<with variable="selection">
<iterate operator="and">
<adapt type="org.eclipse.core.resources.IResource" >
<or>
<test property="org.eclipse.core.resources.name" value="*.java"/>
</or>
</adapt>
</iterate>
</with>
</enabledWhen>
</activity>
<activityPatternBinding activityId="hidedeletepopupmenuID"
isEqualityPattern="false" pattern="org.eclipse.ui.edit.delete">
</activityPatternBinding>
</extension>
This seems to be working fine over project explorer view, but navigator view its not wokring. Can anyone help on this?
Thanks,
darshan
Actions in Navigator view context menu are hard-coded, see ResourceNavigator.fillContextMenu(IMenuManager menu).
Note that the action in popup menu is not the only way to delete a resource (there's also a menu item in Edit menu and key-binding).