Skip to content
Snippets Groups Projects
Commit 666c88a3 authored by Tiziano Munaro's avatar Tiziano Munaro
Browse files

[UI] Introduce JavaFX containment pattern for dynamic loading of views

parent 9c8435e6
No related branches found
No related tags found
1 merge request!823437
......@@ -76,6 +76,7 @@ Export-Package: org.conqat.ide.commons.gef,
org.fortiss.tooling.common.ui,
org.fortiss.tooling.common.ui.javafx,
org.fortiss.tooling.common.ui.javafx.control.treetableview,
org.fortiss.tooling.common.ui.javafx.layout,
org.fortiss.tooling.common.ui.javafx.util
Bundle-Vendor: fortiss GmbH
Bundle-Activator: org.fortiss.tooling.common.ui.ToolingCommonUIActivator
......
FXContainerView.java 4337fdd21f6258c7fed0c3e411fa04d45bc06c90 YELLOW
FXView.java dc5ff1c7c7c60c8203acb5e3e370da31822e0f97 YELLOW
/*-------------------------------------------------------------------------+
| Copyright 2019 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.common.ui.javafx.layout;
import java.io.IOException;
import javafx.scene.layout.Pane;
/**
* JavaFX node of type {@link FXView} including a {@link Pane} which serves as a container for
* another {@link FXView}.
*
* @author munaro
*/
public abstract class FXContainerView<T> extends FXView<T> {
/** Constructor. */
public FXContainerView(FXView<?> containment) throws IOException {
getContainer().getChildren().add(containment.getLayout());
}
/** Returns the {@link Pane} which will act as a container for another {@link FXView}. */
protected abstract Pane getContainer();
}
/*-------------------------------------------------------------------------+
| Copyright 2019 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.common.ui.javafx.layout;
import static org.fortiss.tooling.common.ui.javafx.util.FXMLUtils.load;
import java.io.IOException;
import java.net.URL;
import javafx.fxml.FXML;
import javafx.scene.Node;
/**
* JavaFX node to be included within a container (e.g. a {@link FXContainerView}) and associated
* with a controller of type {@code T}.
*
* @author munaro
*/
public abstract class FXView<T> {
/**
* JavaFX {@link Node} with the layout specified in the {@link FXML} resource and
* associated with a controller of type {@code T}.
*/
private Node layout;
/** Constructor. */
@SuppressWarnings("unchecked")
public FXView() throws IOException {
T controller = (T)this;
URL fxmlResource = controller.getClass().getResource(getFXMLLocation());
layout = load(fxmlResource, controller);
}
/**
* Returns a JavaFX {@link Node} with the layout specified in the {@link FXML} resource and
* associated with a controller of type {@code T}.
*/
public Node getLayout() {
return layout;
}
/** Returns the location of the {@link FXML} resource with the view's layout. */
protected abstract String getFXMLLocation();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment