Proper way to import custom UI into scene builder? - import

I am trying to build an UI with custom control. But having trouble to make the scene builder wo work properly with the custom part.
My custom control:
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="800.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
...other code
</children>
</fx:root>
Room.fxml, which use the custom class:
...other code
<?import ag.ctrl.*?>
<?scenebuilder-classpath-element ../../target/classes/ag/ctrl?>
...other code
<BorderPane prefHeight="200.0" prefWidth="200.0"
BorderPane.alignment="CENTER">
<top>
<TeamArea />
</top>
</BorderPane>
Controller of the custom ui:
package ag.ctrl;
...
public class TeamArea extends AnchorPane {
...
public TeamArea() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(
"/ui/TeamArea.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
...
}
and all those files' path:
TeamArea.fxml: /resource/ui/TeamArea.fxml
Room.fxml: /resource/ui/Room.fxml
TeamArea.class: /target/classes/ag/ctrl/TeamArea.class
I try many different approach before.End up with scene builder's class not found error or others.
Currently I am having an unresolved class error at the TeamArea Node in scene builder.
Some stupid error must in somewhere...
Could any one help?

I think you link to the wrong classpath.
Take a look at this thread
Hope that solves your problem.

Your classpath needs to be:
<?scenebuilder-classpath-element ../../target/classes?>
However, I'm facing the same problem and it doesn't work that way either. Please drop me a comment if you got it working

Related

Creating a admin controller using adminhtml id

I'm trying to add a controller accessible on admin menu through url:
https://dev.m2t2.com/admin_k1tgag/admin/helloWorld/index/key/0195fab99cc865bb756a77e8fe5ceedb6f8eee97de91d569398d383cef4f0d81/
Generated by the XML code inserted below. But it keeps returning
Invalid security or form key. Please refresh the page.
Router.xml :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="adminhtml">
<module name="Study_Admin" before="Magento_Backend"/>
</route>
</router>
</config>
In menu i inserted:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Study_Admin::greetings" title="Greetings" translate="title" module="Study_Admin" parent="Magento_Backend::content" sortOrder="50" dependsOnModule="Study_Admin" resource="Study_Admin::greetings"/>
<add id="Study_Admin::greetings_helloworld" title="Hello World" translate="title" module="Study_Admin" parent="Study_Admin::greetings" sortOrder="10" dependsOnModule="Study_Admin" action="adminhtml/helloWorld" resource="Study_Admin::greetings"/>
</menu>
</config>
But when i access the controller through the menu i have no success. I started debugging and i checked that non-custom controllers extends \Magento\Backend\App\Action class to pass validations inside magento routing core flow. I did the same but i still have no success.
Below my controller class:
<?php
namespace Study\Controller\Adminhtml\HelloWorld;
use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
use Magento\Framework\View\Result\Page;
use Magento\Framework\View\Result\PageFactory;
use Magento\Backend\App\Action\Context;
use ‌Magento\Framework\App\ActionInterface;
class Index extends \Magento\Backend\App\Action
{
const MENU_Id = "Study_Admin::greetings_helloworld";
protected $resultPageFActory;
public function __construct(Context $context, PageFactory $resultPageFActory)
{
parent::__construct($context);
$this->resultPageFActory = $resultPageFActory;
}
public function execute()
{
$resultPage = $this->resultPageFActory->create();
$resultPage->setActiveMenu(static::MENU_Id);
$resultPage->getConfig()->getTitle()->prepend(__('Hello World'));
return $resultPage;
// TODO: Implement execute() method.
}
}
The file structure is :
Thanx in advance, and take care.
It works... was just my namespace in Controller's class that had an error
'namespace Study\Admin\Controller\Adminhtml\Helloworld;'

JavaFX RadioButton setSelected() not working

I'm creating a JavaFX FXML application and haven't been able to use the setSelected() method to set one of two radio buttons by default in a toggle group. The toggle group is functioning normally, so it appears the radio button variables are being set correctly. However, radio1 is not selected as expected.
Following are the relevant sections of my application.
System Information
Product Version: NetBeans IDE 8.1 (Build 201510222201)
Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1
Java: 1.8.0_171; Java HotSpot(TM) 64-Bit Server VM 25.171-b11
Runtime: Java(TM) SE Runtime Environment 1.8.0_171-b11
System: Mac OS X version 10.13.4 running on x86_64; UTF-8; en_US (nb)
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="400.0"
xmlns="http://javafx.com/javafx/8.0.141"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="inventory.view.AddPartController">
<fx:define>
<ToggleGroup fx:id="toggleGroup" />
</fx:define>
<children>
<RadioButton fx:id="radio1" mnemonicParsing="false"
onAction="#handleRadio1" prefHeight="30.0" prefWidth="100.0"
text="radio1" toggleGroup="$toggleGroup"
AnchorPane.rightAnchor="125.0" AnchorPane.topAnchor="25.0" />
<RadioButton fx:id="radio2" mnemonicParsing="false"
onAction="#handleRadio2" prefHeight="30.0" prefWidth="100.0"
text="radio2" toggleGroup="$toggleGroup"
AnchorPane.rightAnchor="25.0" AnchorPane.topAnchor="25.0" />
</children>
</AnchorPane>
Controller
package inventory.view;
import inventory.InventorySystem;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
public class AddPartController {
#FXML
private ToggleGroup toggleGroup;
#FXML
private RadioButton radio1;
#FXML
private RadioButton radio2;
#FXML
private void initialize() {
toggleGroup = new ToggleGroup();
radio1 = new RadioButton();
radio1.setToggleGroup(toggleGroup);
radio1.setSelected(true);
radio2 = new RadioButton();
radio2.setToggleGroup(toggleGroup);
}
}
Where am I going wrong?
You are reinitializing the radio button. The FXML will inject the reference, you are then overriding it. You also define the toggle group in your FXML - so you don't need that either.
Change your code to look like this:
#FXML
private void initialize() {
radio1.setSelected(true);
}
Don't initialize the buttons again . These lines would be enough.
#FXML
private void initialize() {
radio1.setToggleGroup(toggleGroup);
radio1.setSelected(true);
radio2.setToggleGroup(toggleGroup);
}

Magento getEvent()->getOrder empty

I'm trying to get an Observer working to see if a payment has been made via check/cheque, I know the Observer is being used as I have a log record to show. However when I try to access the Order it is either empty or will not print to the log file.
app/etc/modules/Foo_Bar.xml
<?xml version="1.0"?>
<config>
<modules>
<Foo_Bar>
<active>true</active>
<codePool>local</codePool>
</Foo_Bar>
</modules>
</config>
app/code/local/Foo/Bar/etc/config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<global>
<models>
<foo_bar>
<class>Foo_Bar_Model</class>
</foo_bar>
</models>
<events>
<sales_order_payment_place_end> <!-- event -->
<observers>
<foo_bar> <!-- unique for event -->
<!-- type: singleton | disable | model -->
<class>foo_bar/observer</class>
<method>SalesOrderPaymentPlaceEnd</method>
</foo_bar>
</observers>
</sales_order_payment_place_end>
</events>
</global>
</config>
app/code/local/Foo/Bar/Model/Observer.php
<?php
class Foo_Bar_Model_Observer
{
public function SalesOrderPaymentPlaceEnd(Varien_Event_Observer $observer)
{
Mage::log('Location: SalesOrderPaymentPlaceEnd');
$order = $observer->getEvent()->getOrder();
Mage::log('order: '.$order);
}
}
The first log works as expected, however I'm sure getOrder() isn't working as my second log entry just prints 'order: '.
Thanks
#James has already commented this..I am explaning
The event "sales_order_payment_place_end" located in "app\code\core\Mage\Sales\Model\Order\Payment.php" .
The event have only one parameter that is Payment. So
$order = $observer->getEvent()->getOrder();
will not work. You need to use
$orderPayment = $observer->getEvent()->getPayment();
What worked for me was below:
public function autoInvoiceForOfflinePayment(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getPayment()->getOrder();
// In my case I was trying to get the payment method code, e.g.
$order->getPayment()->getMethodInstance()->getCode()
}
I hope this helps (Magento EE 1.14.2)
What I discovered, which I forget and often discover again when creating a hook is to look at the line in the file dispatching the event:
e.g. "app\code\core\Mage\Sales\Model\Order\Payment.php"
Mage::dispatchEvent('sales_order_payment_place_end', array('payment' => $this));
So you want to get the event first, then in the array the payment variable:
$order = $observer->getEvent()->getPayment();
From there you can get any public functions in that file, the same principle seems to apply throughout.

How to make JavaFX Applications non-blurry on Retina Display

A JavaFX application appears blurry on the MacBook Pro Retina screen. Is there a way to display the application sharp? In a blog post/comment was mentioned that this is the case currently: http://fxexperience.com/2012/11/retina-display-macbook-pro/
This is the example fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<VBox xmlns:fx="http://javafx.com/fxml">
<MenuBar>
<Menu text="File">
<items>
<MenuItem text="Exit"/>
</items>
</Menu>
</MenuBar>
</VBox>
Example code:
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Scene
import javafx.scene.layout.VBox
import javafx.scene.paint.Color
import javafx.stage.Stage
object CreateFX extends App {
override def main(args: Array[String]) = {
println("CreateFX starting up...")
Application.launch(classOf[CreateFX], args: _*)
}
}
class CreateFX extends Application {
def start(stage: Stage): Unit = {
println("start "+stage)
stage.setTitle("CreateFX")
val root: VBox = FXMLLoader.load(getClass().getResource("MainScreenVBox.fxml"))//new VBox
val scene = new Scene(root, 800, 600)
scene.setFill(Color.GREEN)
stage.setScene(scene)
stage.show()
}
}
Outcome:
Java Version: 1.7.0_21
In the same article in the commentary Richard Blair stated that this was fixed in the latest JavaFX version (available in the EAP of Java 8, downloadable here)

How to change the preferences so that each window displays something different?

I'm trying to override values of preferences, but nothing overrides.
Does anyone know how to fix this?
portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>cool_portlet</portlet-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>com.app.portlet.cool_portlet</resource-bundle>
<portlet-info>
<title>Cool Portlet</title>
</portlet-info>
<portlet-preferences>
<preference>
<name>KEY</name>
<value>TEST</value>
<read-only>false</read-only>
</preference>
</portlet-preferences>
</portlet>
</portlet-app>
portlet-instances.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE deployments PUBLIC "-//JBoss Portal//DTD Portlet Instances 2.6//EN" "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
<deployments>
<deployment>
<instance>
<instance-id>coolPortlet_IMPORT_newInstance</instance-id>
<portlet-ref>cool_portlet</portlet-ref>
<preferences>
<name>KEY</name>
<value>IMPORT</value>
</preferences>
</instance>
</deployment>
<deployment>
<instance>
<instance-id>coolPortlet_EXPORT_newInstance</instance-id>
<portlet-ref>cool_portlet</portlet-ref>
<preferences>
<name>KEY</name>
<value>EXPORT</value>
</preferences>
</instance>
</deployment>
</deployments>
cool_portlet-object.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE deployments PUBLIC "-//JBoss Portal//DTD Portlet Instances 2.6//EN" "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
<deployments>
<deployment>
<parent-ref>comportal.import</parent-ref>
<if-exists>overwrite</if-exists>
<window>
<window-name>impWindow</window-name>
<content>
<content-type>portlet</content-type>
<content-uri>coolPortlet_IMPORT_newInstance</content-uri>
</content>
<region>center</region>
<height>1</height>
<supported-window-states>
<window-state>normal</window-state>
<window-state>maximized</window-state>
<window-state>minimized</window-state>
</supported-window-states>
<initial-window-state>normal</initial-window-state>
</window>
</deployment>
<deployment>
<parent-ref>comportal.export</parent-ref>
<if-exists>overwrite</if-exists>
<window>
<window-name>expWindow</window-name>
<content>
<content-type>portlet</content-type>
<content-uri>coolPortlet_EXPORT_newInstance</content-uri>
</content>
<region>center</region>
<height>1</height>
<supported-window-states>
<window-state>normal</window-state>
<window-state>maximized</window-state>
<window-state>minimized</window-state>
</supported-window-states>
<initial-window-state>normal</initial-window-state>
</window>
</deployment>
</deployments>
MainController.java
#RequestMapping(value = "VIEW")
#Controller(value = "mainController")
public class MainController {
#RenderMapping
public String init(#RequestParam(value = "key", required = false) String key, Model model, PortletRequest request) throws Exception {
PortletPreferences preferences = request.getPreferences();
String preferencesKey = preferences.getValue("KEY", "Not Found!!!");
System.out.println("KEY is : " + preferencesKey);
model.addAttribute("preferencesKey", preferencesKey);
return "index";
}
}
Output:
13:49:54,860 INFO [STDOUT] KEY is : TEST
13:50:21,088 INFO [STDOUT] KEY is : TEST
You need to call setValue and then store your PortletPreferences object. Note that preferences can only be stored in action phase. visit