I want to build a custom renderer for some of my grids columns to hide the text if the user doesn't have the right to read it. It's still important that the data is accessible even if the user is not able to read it.
So I wrote a custom renderer which looks like this:
package <package>.util.renderer;
import com.vaadin.client.renderers.Renderer;
import com.vaadin.client.widget.grid.RendererCellReference;
import <package>.util.CustomSecurityConstants;
import <package>.BaseUI;
public class BlockedStringRendererClient implements Renderer<String> {
private boolean canReadBlocked = BaseUI.getCurrentPrincipal().get().getAuthorities().contains(CustomSecurityConstants.READ_PERMISSION_BLOCKED);
#Override
public void render(RendererCellReference rendererCellReference, String s) {
if (canReadBlocked) {
rendererCellReference.getElement().setInnerText(s);
} else {
rendererCellReference.getElement().setInnerText("");
}
}
}
Then I wrote the server side of the renderer, following this tutorial https://vaadin.com/docs/-/part/framework/clientsidewidgets/clientsidewidgets-grid.html
package <package>.util.renderer;
import com.vaadin.ui.Grid;
public class BlockedStringRendererServer extends Grid.AbstractRenderer<String> {
public BlockedStringRendererServer() {
super(String.class);
}
}
And finally the connector to connect these components:
package <package>.util.renderer;
import com.vaadin.client.connectors.AbstractRendererConnector;
import com.vaadin.shared.ui.Connect;
#Connect(BlockedStringRendererServer.class)
public class BlockedStringRendererConnector extends AbstractRendererConnector<String> {
#Override
public BlockedStringRendererClient getRenderer() {
return (BlockedStringRendererClient) super.getRenderer();
}
}
But now when I try to use the connector like follows:
grunddatenGrid.getColumn("name").setRenderer(new BlockedStringRendererServer());
The grid doesn't show any columns that contains strings anymore.
I really don't know what I'm doing wrong but I think it might has to do with the Connector-Annotation not working as expected because when I try to debug the client side logic it doesn't even get called.
Can somebody point me to what steps I'm missing?
Kind regards,
Fabian
Related
I've tried to modify minecraft by adding a new item called "uranium". Therefore I created the class "Trauma.java" in the main package and a few other classes listed below.
All packages and classes:
Package Explorer
Trauma.java
package main;
import items.ItemUranium;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import proxy.ServerProxy;
#Mod(modid = Trauma.MODID)
public class Trauma {
public static final String MODID = "Trauma";
#SidedProxy(clientSide = "proxy.ClientProxy", serverSide = "proxy.ServerProxy")
public static ServerProxy proxy;
public static ItemUranium uranium = new ItemUranium();
#EventHandler
public void preInit(FMLPreInitializationEvent event) {
GameRegistry.register(uranium);
}
#EventHandler
public void init(FMLInitializationEvent event) {
proxy.registerClientStuff();
}
#EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
}
BasicItem.java
package items;
import net.minecraft.item.Item;
public class BasicItem extends Item {
public BasicItem(String name) {
setUnlocalizedName(name);
setRegistryName(name);
}
}
ItemUranium.java
package items;
public class ItemUranium extends BasicItem {
public ItemUranium() {
super("uranium");
}
}
ClientProxy.java
package proxy;
import items.BasicItem;
import main.Trauma;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
public class ClientProxy extends ServerProxy {
#Override
public void registerClientStuff () {
registerItemModel(Trauma.uranium);
}
public static void registerItemModel(BasicItem item) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Trauma.MODID + ":" + item.getRegistryName(), "inventory"));
}
}
ServerProxy.java
package proxy;
public class ServerProxy {
public void registerClientStuff() {}
}
uranium.json
{
"parent": "item/generated",
"textures": {
"layer0": "Trauma:items/uranium"
}
}
uranium.png
ingame
Also I don't know why the item in inventory isn't called uranium...
I spent two hours on fixing the problem and it didn't help so it would be really nice if somebody of you may help me.
Thanks :)
Don't use the Model Mesher:
The model mesher is Vanilla (Mojang) code and using it correctly has always been finicky and unreliable, failing if you called it too early and failing if you called it too late. So Forge added the ModelLoader class to resolve that problem.
Replace this line:
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(...)
With this line:
ModelLoader.setCustomModelResourceLocation(...)
The ... contents are identical.
Second, depending on what version of Minecraft you're using, you should...:
Stop using GameRegistry.Register
Instead use the RegistryEvent.Register<T> events (where <T> will be <Block> to register blocks, <Item> to register items, etc)
Register your models in the ModelRegistryEvent and no where else.
This event is #SideOnly(CLIENT) and can be subscribed to in your client proxy, avoiding the need to forward references through your proxy class. Eg. I do it like this, where lines 197-199 is the most common scenario needed, where the array is populated during the item registration event. The rest of that method handles the custom state mappers and custom mesh definitions that are used by only a handful of items/blocks and not relevant here.
Include your Mod ID in your unlocalized name. The best way to do this would be setUnlocalizedName(getRegistryName().toString());
See also the Forge documentation on events.
In Sonar 4.5.6 (with default settings) I am seeing Duplicated Blocks message as
My java code for which I am getting the message is like below:-
package com.jabong.orchestratorservice.adapter.order.endpoints;
import com.jabong.orchestratorservice.adapter.order.request.UpdateOrderStatusReadyShipRequest;
public class UpdateOrderReadyShipEndPoint extends BaseOrderEndPoint {
private final static String API_NAME = "setStatusToReadyToShip";
#Override
public String getSourceEndPoint() {
return new StringBuilder("direct:").append(API_NAME).toString();
}
#Override
public String getDestinationEndPoint() {
return new StringBuilder("bean:orderHelper?method=").append(API_NAME).toString();
}
#Override
protected String getName() {
return API_NAME;
}
#Override
protected String getApiInputClassName() {
return UpdateOrderStatusReadyShipRequest.class.getName();
}
}
UpdateOrderStatusReadyShipRequest also does not import UpdateOrderReadyShipEndPoint
package com.jabong.orchestratorservice.adapter.order.request;
public class UpdateOrderStatusReadyShipRequest extends BaseOrderRequest {
Can some let me know what does this mean?
The Duplicate Blocks rule raises issues at the file level. So it's not trying to tell you that your import statement is duplicated, but that somewhere in the file is a duplicate block. If you'll scroll down, you should see a vertical yellow/orange bar in the left margin. It marks the duplicate block. Click on the bar to get details of where the block is duplicated.
EDIT In more recent versions the duplication marker is brown or gray.
You have to look (scroll down) your code. There will be a duplication marker in brown/gray like this:
I am trying to track all of the supplies stored in a knapsack object and create an interface that shows the supplies update using an observer/observable implementation. For some reason when I run this code, with 2 items in the knapsack, the second item updates and shows expiration date decreasing as time change is triggered. The first one does not change at all, as if it's a static label. Please could someone let me know what I did wrong? Thanks so much for your help in advance! Also, I'm super new to Java programming so please extra information/explanation would be greatly appreciated.
Here is my code:
package view;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import supplies.Supplies;
import model.Adventure;
import model.Knapsack;
public class InventoryView extends JPanel implements Observer{
private Knapsack knapsack;
private Adventure adventure;
private JLabel b;
public InventoryView(Adventure adventure) {
this.adventure=adventure;
this.knapsack=adventure.getSquad().getKnapsack();
for (Supplies supply : knapsack.getSupplies()) {
b=new JLabel(supply.toString());
add(b);
}
knapsack.addObserver(this);
}
#Override
public void update(Observable arg0, Object arg1) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
for (Supplies supply : knapsack.getSupplies()) {
b.setText(supply.toString());
add(b);
}
}
});
}
}
Swing is lazy when it comes to container updates (add/removes), this allows you to execute a number of add/removes in quick succession without fear that the system will grind to a halt while it attempts to update the entire container hierarchy on each call.
Call revalidate and repaint after you have added all your components. Also, make sure that your JPanel is using a layout manager capable of supporting multiple children.
You might consider using a JList or JTable instead
I starting to use FEST to help me to perform unit test on my Java Swing GUI.
For now, I managed to get through the documentation (mostly deprecated) and help me by looking at the Javadoc and the code.
Right now I am stuck on a problem while using the NoExitSecurityManager. The documentation is quite out dated but we can understand the big lines of it.
I simply try to test if my "Quit" MenuItem is working well in my GUI. So, I need to block the System.exit(0) and map the exit status of the program to a JUnit test.
Here is a simplified code I use to perform the test (the tested class is GraphicalUserInterface).
import org.junit.Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.fest.swing.annotation.RunsInEDT;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.junit.testcase.FestSwingJUnitTestCase;
import org.fest.swing.security.NoExitSecurityManagerInstaller;
public class GraphicalUserInterfaceTest extends FestSwingJUnitTestCase {
private static FrameFixture gui;
private static NoExitSecurityManagerInstaller noExitSecurityManagerInstaller;
#BeforeClass
public static void setUpBeforeClass() throws Exception {
NoExitSecurityManagerInstaller.installNoExitSecurityManager(new ExpectExitSuccess());
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
noExitSecurityManagerInstaller.uninstall();
}
#Override
protected void onSetUp() {
gui = new FrameFixture(robot(), createNewGUI());
gui.show();
}
#RunsInEDT
private GraphicalUserInterface createNewGUI() {
return GuiActionRunner.execute(new GuiQuery<GraphicalUserInterface>() {
protected GraphicalUserInterface executeInEDT() {
return new GraphicalUserInterface();
}
});
}
#Test
public final void testFileMenuQuitMenuItem() {
gui.menuItemWithPath("File", "Quit").click();
}
}
The ExitCallHook are coded like this (you can guess the other one easily).
import static org.junit.Assert.assertTrue;
import org.fest.swing.security.ExitCallHook;
public final class ExpectExitSuccess implements ExitCallHook {
#Override
public void exitCalled(int status) {
assertTrue(status == 0);
}
}
All the tests are performed well and everything seems to be ok except that I get a java.lang.NullPointerException at the end.
So, I wonder what did I do wrong (or what can I improve to not get this nullpointer exception at the end of the test).
I found the solution in the code. In fact, the proper way to do it is the following:
#Test
public final void testFileMenuQuitMenuItem() {
NoExitSecurityManagerInstaller noExitSecurityManagerInstaller =
NoExitSecurityManagerInstaller.installNoExitSecurityManager(new ExpectExitSuccess());
gui.menuItemWithPath("File", "Quit").click();
noExitSecurityManagerInstaller.uninstall();
}
This way prevent to pollute each test with a NoExitSecurityManager.
I want to create a very simple RMI code which just share the desktop.
I have created my classes and also remote interface.in the Share class ,I have an execute method which will return the image of the client's desktop.but I don't know that how can I get that image ?or how can i store it?
please help me,thanks.
Share class:
class Share implements Task<DesktopPaneUI>,Serializable{
public Share(){
}
public DesktopPaneUI execute() {
}
}
Task class:
public interface Task<T> {
T execute();
}
import java.awt.*
import java.awt.image.*
BufferedImage screenShot = new Robot().createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())
)