public code v1

This commit is contained in:
2026-05-22 11:14:29 +02:00
parent 427197ec5a
commit b8141736eb
28859 changed files with 575079 additions and 0 deletions
@@ -0,0 +1,42 @@
package afryca.rcp.addon;
import javax.annotation.PostConstruct;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.swt.widgets.Shell;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
/**
* {@lin khttp://stackoverflow.com/questions/15894393}
*/
public class MinSizeAddon {
private static final int WIDTH = 900;
private static final int HEIGHT = 600;
@PostConstruct
public void init(final IEventBroker eventBroker) {
EventHandler handler = new EventHandler() {
@Override
public void handleEvent(Event event) {
if (!UIEvents.isSET(event))
return;
Object objElement = event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(objElement instanceof MWindow))
return;
MWindow windowModel = (MWindow) objElement;
Shell theShell = (Shell) windowModel.getWidget();
if (theShell == null)
return;
theShell.setMinimumSize(WIDTH, HEIGHT);
}
};
eventBroker.subscribe(UIEvents.UIElement.TOPIC_WIDGET, handler);
}
}
@@ -0,0 +1,58 @@
package afryca.rcp.addon;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.di.extensions.EventTopic;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.e4.ui.workbench.UIEvents.EventTags;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.osgi.service.event.Event;
/**
* Set active perspective in <code>active.perspective</code> property.
*/
public class PerspectiveSwitchAddon {
private static final String PERSPECTIVE_STACK_ID = "afryca.rcp.main.perspectivestack"; //$NON-NLS-1$
private static final String ACTIVE_PERSPECTIVE_PROPERTY = "active.perspective"; //$NON-NLS-1$
@Inject
private IEclipseContext context;
@Inject
private EModelService modelService;
@Inject
private MApplication application;
@Inject
private IEventBroker eventBroker;
@PostConstruct
public void setActivePerspectiveProperty() {
MPerspectiveStack stack = (MPerspectiveStack) modelService.find(PERSPECTIVE_STACK_ID, application);
MPerspective active = stack.getSelectedElement();
context.set(ACTIVE_PERSPECTIVE_PROPERTY, (active != null) ? active.getElementId() : null);
context.declareModifiable(ACTIVE_PERSPECTIVE_PROPERTY);
eventBroker.post(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);
}
@Inject
@Optional
public void subscribeTopicSelectedElement(
@EventTopic(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT) Event event) {
Object value = event.getProperty(EventTags.NEW_VALUE);
if (value instanceof MPerspective) {
context.modify(ACTIVE_PERSPECTIVE_PROPERTY, ((MPerspective) value).getElementId());
eventBroker.post(UIEvents.REQUEST_ENABLEMENT_UPDATE_TOPIC, UIEvents.ALL_ELEMENT_ID);
}
}
}