SCViewer/plugins/com.minres.scviewer.e4.appl.../src/com/minres/scviewer/e4/application/handlers/EnableHover.java

46 lines
1.5 KiB
Java
Raw Normal View History

2020-03-21 11:30:30 +01:00
package com.minres.scviewer.e4.application.handlers;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;
2020-06-21 15:37:38 +02:00
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2020-03-21 11:30:30 +01:00
import org.eclipse.e4.core.di.annotations.Execute;
2020-06-21 15:37:38 +02:00
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.di.extensions.Preference;
2020-03-21 11:30:30 +01:00
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledItem;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
2020-06-21 15:37:38 +02:00
import org.osgi.service.prefs.BackingStoreException;
2020-03-21 11:30:30 +01:00
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
2020-06-21 15:37:38 +02:00
@SuppressWarnings("restriction")
2020-03-21 11:30:30 +01:00
public class EnableHover {
static final String TAG_NAME = "EnableHover"; //$NON-NLS-1$
@Inject
MApplication application;
2020-06-21 15:37:38 +02:00
@Inject
@Optional
public void reactOnShowHoverChange(EModelService modelService, @Preference(value = PreferenceConstants.SHOW_HOVER) Boolean hover) {
2020-03-21 11:30:30 +01:00
List<String> tags = new LinkedList<>();
tags.add(TAG_NAME);
List<MHandledItem> elements = modelService.findElements(application, null, MHandledItem.class, tags );
for( MHandledItem hi : elements ){
2020-06-21 15:37:38 +02:00
hi.setSelected(hover);
2020-03-21 11:30:30 +01:00
}
}
@Execute
2020-06-21 15:37:38 +02:00
public void execute(MHandledItem handledItem, @Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE) IEclipsePreferences prefs ) {
try {
prefs.putBoolean(PreferenceConstants.SHOW_HOVER, handledItem.isSelected());
prefs.flush();
} catch (BackingStoreException e) {}
2020-03-21 11:30:30 +01:00
}
}