Incorporate directional buttons into an AbstractCell

In the creation of an AbstractCell<String>, I have successfully implemented a header displaying "Welcome to your mobile...". Now, I am interested in incorporating two buttons within this AbstractCell: one for navigating back to the previous page and another for returning to the welcome page. The current implementation involves extending a class that utilizes AbstractCell<String>, as shown in the code snippet below:

public class HeaderCell extends AbstractCell<String> {
    
    // Templates interface definition
    interface Templates extends SafeHtmlTemplates {

        String style = "HeaderPanel";

        @SafeHtmlTemplates.Template("<div class=\""+style+"\">{0}</div>")
        SafeHtml cell(SafeHtml value);
    }

    private Templates templates = GWT.create(Templates.class);

    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context,
            String value, SafeHtmlBuilder sb) {
        SafeHtml safeValue = SafeHtmlUtils.fromString(value);

        SafeHtml rendered = templates.cell(safeValue);

        sb.append(rendered);
    }
}

My main query pertains to whether there exists any method to integrate the aforementioned two buttons into the header cell design. Additionally, please take note of the black-colored styling applied to the header cell. PS: To achieve the visual appearance resembling the image provided, the following CSS rules are used:

.HeaderPanel {
    -moz-box-shadow: inset -1px -1px 15px 1px #ffffff;
    -webkit-box-shadow: inset -1px -1px 15px 1px #ffffff;
    box-shadow: inset -1px -1px 15px 1px #ffffff;
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #242524), color-stop(1, #242524));
    background: -moz-linear-gradient(center top, #242524 5%, #242524 100%);
    background-color: #242524;
    -moz-border-radius: 7px;
    -webkit-border-radius: 7px;
    border-radius: 7px;
    border: 1px solid #dcdcdc;
    color: #ffffff;
    font-family: arial;
    font-size: 17px;
    font-weight: bold;
    padding: 8px 36px;
    text-decoration: none;
    text-shadow: 1px 1px 29px #ffffff;
    text-align: center;
}

Answer №1

This particular approach may not be the most optimal, but it gets the job done for me. -- To start, insert the following code snippet into your constructor:

public HeaderCell() {
   super("click", "keydown");
}

-- Next, you'll need to override the onBrowserEvent method:

@Override
    public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
      // Delegate keydown event handling to AbstractCell.
      super.onBrowserEvent(context, parent, value, event, valueUpdater);   
      // Now let's handle the click event.
      if ("click".equals(event.getType())) {
        EventTarget eventTarget = event.getEventTarget();
       // Here we verify that only the image within the cell was clicked, not the entire cell
        if(eventTarget.toString().contains("img src") && !eventTarget.toString().contains("<div class")){
            // Implement actions specific to clicking the image
        }
      }
    }

Cheers, Lin

Answer №2

Have you considered using CompositeCell along with ActionCells for your button functionality?

http://example.com/composite-cell-action-cells

Create a new instance of CompositeCell<C> and initialize it with Arrays.<HasCell<C, ?>>asList(
    new IdentityColumn<C>(new ActionCell<C>("<", new Delegate<C>() { ... })),
    new Column<C, String>(new HeaderCell()) { ... },
    new IdentityColumn<C>(new ActionCell<C>(">", new Delegate<C>() { ... }))
));

Answer №3

// Generating a new button element 
Element newButton = DOM.createButton(); 

// Customizing the HTML content of the button
newButton.setInnerHTML(<"button type="button">Click Here! <"/button>");

// Appending the button to safehtmlbuilder
sb.appendHtmlConstant(newButton.getInnerHTML());

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Clearing information from a database through jsp

Looking to remove a specific record from the database? Below is my code snippet: <% String value = request.getParameter("Meter_No"); int v=Integer.parseInt(value); try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDirver"); Connection conn = D ...

Ensuring an adjustable iframe with maximum width and height

In order to ensure that both images and iframes within a fixed height container are responsive and do not overflow vertically or horizontally, you can apply the following CSS: img { max-width: 100%; max-height: 100%; } This CSS rule will prevent ...

How to assign a value to a variable in Angular after the view

Situation: In the current setup of my website, I have implemented two tabs each containing text with a fixed height and enabled content-overflow hidden. Problem: My goal is to add three dots (icon) when the text overflows. To achieve this, I utilize an ex ...

Tips for inserting CSS into Django's UpdateView or CreateView forms

I have a project on the go, and the designer has handed me the design. I need to replicate the input forms from the design, which requires adding CSS to my form object. If I am using a Django class-based view, how can I add custom CSS to the form fields l ...

Fade in images smoothly

Currently, I am in the process of creating a visually appealing image "slider" for a landing page on one of my websites. The slider that I have already created is fully functional and successful, but I am looking to take it up a notch... My goal is to inc ...

Ways to identify the user who initiated the command in onButtonInteraction

https://i.sstatic.net/PQEQD.png Attempted to retrieve the user using event.getMessage().getReferencedMessage().getUser(), however encountered a Nullpointerexception. I also attempted to obtain it with event.getJDA().getUserByTag(), but if there is a space ...

Using the equals() method to compare two strings can result in a Null Pointer Exception

I am facing an issue with my app where it crashes when I try to compare two strings using the `.equals()` method. The two Strings are present in separate classes. class Land { String land1; String land2; int a; } Land l = new Land(); public ...

What is the best way to arrange a particular div in front of another div?

My current dilemma involves the need to position <div id="content1"> directly before <div id="content2">. However, the issue arises from the fact that <div id="content2"> is nested within another div, rendering traditional CSS push and pu ...

How can I ensure the footer stays at the bottom of the page using a table layout?

For quite some time now, I've been working on achieving a table layout with a sticky footer. My specific requirement is for the footer to remain fixed at the bottom even when zooming in or out. However, whenever I try to adjust the zoom level of the w ...

Encountering difficulties with implementing and utilizing bootstrap in Symfony 5.3 with Encore plugin

While I am currently dealing with an older version of Symfony, I decided to create a new 5.3 Symfony application from scratch. However, I am facing difficulties when trying to integrate bootstrap into it. After consulting some documentation, I proceeded to ...

Exploring Java inheritance for newcomers

Currently, I am in the process of developing a project for creating a software similar to cloudShare. In this project, we have two types of users: Basic and Premium. Basic users are limited to 2GB of space, while Premium users have 5GB of space. Basic me ...

WildFly was unable to spawn a new process for establishing the connection

I am encountering a recurring issue on my OpenShift instance running a WildFly application and PostgreSQL. The problem is reflected in the server log as: Caused by: org.postgresql.util.PSQLException: Connection rejected: could not fork new process for con ...

The image is overlapping the link, but I want to make sure the link is clickable

I am facing an issue with the positioning of my logo on the top of my webpage. The logo has letters that hang down over the menu bar, particularly a 'y'. Without any complex coding, I have managed to adjust the heights of the containers to make i ...

The project has not been developed using Eclipse

I am attempting to execute my plugin project as an application using a handler class: @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(e ...

What are the steps to showcase an image stored in the drawable folder in fullscreen mode within a viewpager application?

I recently created an application that is intended to display images to users using a viewpager. However, I am facing an issue where the images are not being displayed in full-screen mode. Can someone kindly provide me with the necessary code adjustments t ...

Navigating through Excel download prompts with Selenium WebDriver

What is the best way to deal with an Excel download popup when using Selenium WebDriver? ...

I've tried to hide the sub-menu initially using display:none in CSS, and then show it using display: block on hover. However, for some reason,

I have set the sub-menu to be hidden with display: none, and it should show on hover with display: block, but for some reason, it's not working as expected. To make the sub-menu appear when hovering over main-menu-link, you can use the following HTML ...

Utilizing Selenium with Java: Extracting Excel Data using Annotations

Employing DataProvider annotation along with gradle as Dependency Manager. I have some inquiries: Is it necessary to download jxl in order to read data from an excel file? If attempting to read a URL (located within a cell) from an excel file, will the U ...

Tips for guaranteeing that a method is only utilizing one instance at any given time

I have a simple question regarding a class method called task. I want to ensure that only one instance of this class can run the method at a time. Below is my implementation – could you please confirm if it is correct? class A{ public void task(){ ...

Is there a way to modify the font size of Vuetify inputs within a specific component?

After creating a Vuetify Textfield component, I realized that the default font size is too large for my application. I attempted to decrease the label and text sizes by using the following CSS: .v-text-field input { font-size: 10px; } However, I encou ...