I want to create a plugin using biometric authentication (Biometric) provided by Google and implement it in Unity - unity3d

I would like to implement biometric authentication using the biometrics provided by Googole, but I am having trouble getting it to work.
The following is a reference site on biometrics.
https://developer.android.com/jetpack/androidx/releases/biometric
I've never made an Android plugin before, and I'm having a hard time finding information on how to integrate with Unity.
I'm testing it with the following code
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/activity/ComponentActivity;
java.lang.ClassNotFoundException: androidx.activity.ComponentActivity
I'm getting an error and don't know how to fix it.
Please help me. Please help me.
◇MainActivity.java
package com.example.biometricslibs;
import android.content.Context;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricPrompt;
import androidx.fragment.app.FragmentActivity;
import java.util.concurrent.Executor;
public class MainActivity {
public static MainActivity instance() {
return new MainActivity();
}
private Executor executor = new MainThreadExecutor();
private BiometricPrompt biometricPrompt;
private BiometricPrompt.AuthenticationCallback callback = new BiometricPrompt.AuthenticationCallback() {
#Override
public void onAuthenticationError(int errorCode, #NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
if (errorCode == 13 && biometricPrompt != null)
biometricPrompt.cancelAuthentication();
}
#Override
public void onAuthenticationSucceeded(#NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
}
#Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
};
public void BiometricCheck(Context context) {
Toast.makeText(context, "call", Toast.LENGTH_SHORT).show();
biometricPrompt = new BiometricPrompt((FragmentActivity) context, executor, callback);
BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("title")
.setSubtitle("subTitle")
.setDescription("description")
.setNegativeButtonText("cancel")
.build();
biometricPrompt.authenticate(promptInfo);
}
}
◇MainThreadExecutor.java
package com.example.biometricslibs;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.Executor;
public class MainThreadExecutor implements Executor {
private final Handler handler = new Handler(Looper.getMainLooper());
#Override
public void execute(Runnable r) {
handler.post(r);
}
}
◇UnityC#
using(var nativeDialog = new AndroidJavaClass("com.example.biometricslibs.MainActivity"))
{
using(var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using(var currentUnityActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
using(var instance = nativeDialog.CallStatic<AndroidJavaObject>("instance"))
{
instance.Call(
"BiometricCheck",
currentUnityActivity
);
}
}
}
}

Related

Use Datawedge with flutter

I am trying to use the datawedge intent API with my flutter application, on a Zebra android scanner. I started to use the Zebra EMDK API from a git repository, which works perfectly. Now I want to migrate it (which is recommended by Zebra) because I want it to be also available on mobiles (if it is possible).
I am trying to follow the instructions from this page and merge it with the code from the git repo, but no scan event is detected in my app.
Has someone already done this and could help me?
Here is my MainActivity.java:
package com.example.test_datawedge;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
// import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.EventChannel.EventSink;
import io.flutter.plugin.common.EventChannel.StreamHandler;
import io.flutter.plugins.GeneratedPluginRegistrant;
import java.util.ArrayList;
public class MainActivity extends FlutterActivity {
private static final String BARCODE_RECEIVED_CHANNEL = "samples.flutter.io/barcodereceived";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
// setContentView(R.layout.activity_main);
IntentFilter filter = new IntentFilter();
filter.addCategory(Intent.CATEGORY_DEFAULT);
filter.addAction(getResources().getString(R.string.activity_intent_filter_action));
// registerReceiver(myBroadcastReceiver, filter);
new EventChannel(getFlutterView(), BARCODE_RECEIVED_CHANNEL).setStreamHandler(
new StreamHandler() {
private BroadcastReceiver barcodeBroadcastReceiver;
#Override
public void onListen(Object arguments, EventSink events) {
Log.d("FLUTTERDEMO", "EventChannelOnListen");
barcodeBroadcastReceiver = createBarcodeBroadcastReceiver(events);
registerReceiver(
barcodeBroadcastReceiver, new IntentFilter("readBarcode"));
}
#Override
public void onCancel(Object arguments) {
Log.d("FLUTTERDEMO", "EventChannelOnCancel");
unregisterReceiver(barcodeBroadcastReceiver);
barcodeBroadcastReceiver = null;
}
}
);
}
// #Override
// protected void onDestroy()
// {
// super.onDestroy();
// unregisterReceiver(myBroadcastReceiver);
// }
//
// After registering the broadcast receiver, the next step (below) is to define it.
// Here it's done in the MainActivity.java, but also can be handled by a separate class.
// The logic of extracting the scanned data and displaying it on the screen
// is executed in its own method (later in the code). Note the use of the
// extra keys are defined in the strings.xml file.
//
private BroadcastReceiver createBarcodeBroadcastReceiver(final EventSink events) {
return new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.d("FLUTTERDEMO", "createBarcodeBroadcastReceiver " + action);
if(action.equals("readBarcode")){
String barcode = intent.getStringExtra("barcode");
String barcodetype = intent.getStringExtra("barcodetype");
Log.d("FLUTTERDEMO", "createBarcodeBroadcastReceiver " + barcode);
events.success(barcode);
}
}
};
}
//
// The section below assumes that a UI exists in which to place the data. A production
// application would be driving much of the behavior following a scan.
//
// private void displayScanResult(Intent initiatingIntent, String howDataReceived)
// {
// String decodedSource = initiatingIntent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_source));
// String decodedData = initiatingIntent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_data));
// String decodedLabelType = initiatingIntent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_label_type));
// final TextView lblScanSource = (TextView) findViewById(R.id.lblScanSource);
// final TextView lblScanData = (TextView) findViewById(R.id.lblScanData);
// final TextView lblScanLabelType = (TextView) findViewById(R.id.lblScanDecoder);
// lblScanSource.setText(decodedSource + " " + howDataReceived);
// lblScanData.setText(decodedData);
// lblScanLabelType.setText(decodedLabelType);
// }
}
Zebra EMDK retrieves data by overriding the 'onStatus' and 'onData' functions.
Retrieve your barcode data from 'onData'

Getting user data in NewProjectCreationPage in Eclipse Plugin

I have been successful in making a plugin. However now i need that on project creation page i add some more textboxes to get the user information. Also i need to use this information to add into the auto generated .php files made in project directory.
I want to know how can i override the WizardNewProjectCreationPage to add some more textboxes to the already given layout. I am pretty new to plugin development. Here is the code for my custom wizard.
import java.net.URI;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
import rudraxplugin.pages.MyPageOne;
import rudraxplugin.projects.RudraxSupport;
public class CustomProjectNewWizard extends Wizard implements INewWizard, IExecutableExtension {
private WizardNewProjectCreationPage _pageOne;
protected MyPageOne one;
private IConfigurationElement _configurationElement;
public CustomProjectNewWizard() {
// TODO Auto-generated constructor stub
setWindowTitle("RudraX");
}
#Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
// TODO Auto-generated method stub
}
#Override
public void addPages() {
super.addPages();
_pageOne = new WizardNewProjectCreationPage("From Scratch Project Wizard");
_pageOne.setTitle("From Scratch Project");
_pageOne.setDescription("Create something from scratch.");
addPage(one);
addPage(_pageOne);
}
#Override
public boolean performFinish() {
String name = _pageOne.getProjectName();
URI location = null;
if (!_pageOne.useDefaults()) {
location = _pageOne.getLocationURI();
System.err.println("location: " + location.toString()); //$NON-NLS-1$
} // else location == null
RudraxSupport.createProject(name, location);
// Add this
BasicNewProjectResourceWizard.updatePerspective(_configurationElement);
return true;
}
#Override
public void setInitializationData(IConfigurationElement config,
String propertyName, Object data) throws CoreException {
_configurationElement = config;
// TODO Auto-generated method stub
}
}
Ask for any other code required. Any help is appreciated. Thank You.
Instead of using WizardNewProjectCreationPage directly create a new class extending WizardNewProjectCreationPage and override the createControl method to create new controls:
class MyNewProjectCreationPage extends WizardNewProjectCreationPage
{
#Override
public void createControl(Composite parent)
{
super.createControl(parent);
Composite body = (Composite)getControl();
... create new controls here
}
}

Eclipse 4 RCP - application does not have active window

I want to have some helper functions for manipulating UI.
I don't want to pass to them any parameters except what is necessary by my domain model (i don't want to pass EModelService, EPartService etc.)
Question: The problem is i am getting exception application does not have active window.
I found where the problem is.
It happend because i am manipulating parts via EPartService accessed from the application context IWorkbench.getApplication().getContext().get(EPartService.class).
THIS IS IMPORTANT: Currently i am getting that exception when i am trying to modify my UI AFTER i read inputs from dialog. Pleas note that the error does not happened when i am trying to modify the UI just BEFORE i
opened the dialog. Look at the code, i added some comments.
NewFromDirectoryDialog.java
package cz.vutbr.fit.xhriba01.bc.handlers;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import cz.vutbr.fit.xhriba01.bc.BcModel;
import cz.vutbr.fit.xhriba01.bc.resolvers.filesystem.FileSystemResolver;
import cz.vutbr.fit.xhriba01.bc.ui.dialogs.NewFromDirectoryDialog;
import cz.vutbr.fit.xhriba01.bc.ui.UI;
public class NewFromDirectoryHandler {
#Execute
public void execute(MApplication application, EPartService partService, #Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
FileSystemResolver fsr = new FileSystemResolver("/home/jara/git/cz.vutbr.fit.xhriba01.bc/bc/src",
"/home/jara/git/cz.vutbr.fit.xhriba01.bc/bc/bin");
BcModel.setResolver(fsr);
// THIS CALL IS OK AND EVERYTHING WORKS
UI.changeExplorerView("bc.partdescriptor.filesystemview", fsr);
NewFromDirectoryDialog dialog = new NewFromDirectoryDialog(shell);
dialog.create();
if (dialog.open() == Window.OK) {
String sourceDir = dialog.getSourceDir();
String classDir = dialog.getClassDir();
FileSystemResolver fsr = new FileSystemResolver(classDir, sourceDir);
//THIS CALL LEADS TO EXCEPTION: application does not have active window
UI.changeExplorerView("bc.partdescriptor.filesystemview", fsr);
}
}
}
That EPartService from application context is based on org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl
and not on org.eclipse.e4.ui.internal.workbench.PartServiceImpl
as EPartService instance you get when injected to #PostConstruct annotated method on Part's view.
org.eclipse.e4.ui.internal.workbench.ApplicationPartServiceImpl (not entire source code)
You can see that the error probably happened because at the time ApplicationPartServiceImpl.createPart is called in my UI.changeExplorerView, the Eclipse runtime does not know what window
is currently active.
package org.eclipse.e4.ui.internal.workbench;
import java.util.Collection;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.IEclipseContext;
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.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MInputPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.IPartListener;
public class ApplicationPartServiceImpl implements EPartService {
private MApplication application;
#Inject
ApplicationPartServiceImpl(MApplication application) {
this.application = application;
}
private EPartService getActiveWindowService() {
IEclipseContext activeWindowContext = application.getContext().getActiveChild();
if (activeWindowContext == null) {
throw new IllegalStateException("Application does not have an active window"); //$NON-NLS-1$
}
EPartService activeWindowPartService = activeWindowContext.get(EPartService.class);
if (activeWindowPartService == null) {
throw new IllegalStateException("Active window context is invalid"); //$NON-NLS-1$
}
if (activeWindowPartService == this) {
throw new IllegalStateException("Application does not have an active window"); //$NON-NLS-1$
}
return activeWindowPartService;
}
#Override
public MPart createPart(String id) {
return getActiveWindowService().createPart(id);
}
}
LifeCycleManager.java (how i initialize the UI helper class)
You can see i am injecting IWorkbench to my UI class.
IWorkbench allows me to access MApplication, so that is all i should
need to modify app UI.
package cz.vutbr.fit.xhriba01.bc;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.e4.ui.workbench.UIEvents;
import cz.vutbr.fit.xhriba01.bc.ui.UI;
public class LifeCycleManager {
#Inject
#Optional
private void appCompleted(#UIEventTopic(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) Object event, IWorkbench workbench) {
ContextInjectionFactory.inject(UI.getDefault(), workbench.getApplication().getContext());
}
}
UI.java
package cz.vutbr.fit.xhriba01.bc.ui;
import javax.inject.Inject;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.jface.text.IDocument;
import cz.vutbr.fit.xhriba01.bc.BcModel;
import cz.vutbr.fit.xhriba01.bc.resolvers.ISourceAndClassResolver;
public class UI {
public static final String PART_EXPLORER_ID = "bc.part.inspector";
public static final String PART_EXPLORER_CONTAINER_ID = "bc.partstack.explorer_stack";
public static final String PART_JAVA_SOURCE_VIEWER_ID = "bc.part.javasourceview";
private static UI fInstance = new UI();
#Inject
private IWorkbench fWorkbench;
private UI() {
}
public static void changeExplorerView(String partDescriptorId, ISourceAndClassResolver resolver) {
EModelService modelService = fInstance.fWorkbench.getApplication().getContext().get(EModelService.class);
EPartService partService = fInstance.fWorkbench.getApplication().getContext().get(EPartService.class);
MApplication application = fInstance.fWorkbench.getApplication();
MPart part = partService.createPart(partDescriptorId);
MPart oldPart = partService.findPart(UI.PART_EXPLORER_ID);
MPartStack partStack = (MPartStack) modelService.find(UI.PART_EXPLORER_CONTAINER_ID, application);
partStack.setVisible(true);
if (oldPart != null) {
partService.hidePart(oldPart);
}
part.setElementId(UI.PART_EXPLORER_ID);
partStack.getChildren().add(part);
BcModel.setResolver(resolver);
partService.showPart(part, PartState.VISIBLE);
}
public static UI getDefault() {
return fInstance;
}
public static void setJavaSourceLabel(String label, EPartService partService) {
MPart part = partService.findPart(UI.PART_JAVA_SOURCE_VIEWER_ID);
if (part != null) {
part.setLabel(label);
}
}
public static void setJavaSourceText(String source) {
IDocument document = BcModel.getJavaDocument();
if (document != null) {
document.set(source);
}
}
}
I think the problem is when i open the dialog, the activeChild changes somehow to that new opened dialog and when i close it and try immediately change my UI, it does not work because the activeChild is still not properly setup back. Otherweise i don't know why it works fine just before i opened the dialog and doesn't work just after the dialog is closed.
Does anyone know if it is bug?

Jenkins Plugin. RootAction. index.jelly in seperate window

i am writing a simple plugin and am forced to create a RootAction which displays a page (the index.jelly) and needs some additional values to confirm and then execute the methode.
My problem is, that the index.jelly file gets always displayed on a blank window.
But i do need it to be included inside of the Jenkinstemplate in the main table, as usual.
Can't seem to figure out why this is happening.
Any ideas?
RestartJksLink.java
package org.jenkinsci.plugins.tomcat_app_restart;
import hudson.Extension;
import hudson.model.ManagementLink;
/**
*
*
* #author [...]
*/
#Extension
public class RestartJksLink extends ManagementLink {
#Override
public String getIconFileName() {
return "/plugin/tomcat-app-restart/images/restart.png";
}
#Override
public String getUrlName() {
return "jksrestart";
}
#Override
public String getDescription() {
return "Restart your Jenkins-Application on Tomcat";
}
public String getDisplayName() {
return "Restart Jenkins-App on Tomcat";
}
}
RestartJksRootAction.java
package org.jenkinsci.plugins.tomcat_app_restart;
import java.io.IOException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import jenkins.model.Jenkins;
import hudson.Extension;
import hudson.model.RootAction;
import hudson.util.FormValidation;
#Extension
public class RestartJksRootAction implements RootAction {
public String getDisplayName() {
return "Restart Jenkins on Tomcat";
}
public String getIconFileName() {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
return null;
}
if (!Jenkins.getInstance().getLifecycle().canRestart()) {
return null;
}
return "/plugin/tomcat-app-restart/images/restart.png";
}
public String getUrlName() {
return "jksrestart";
}
public FormValidation doJksRestart() {
Authenticator.setDefault (new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("admin", "admin".toCharArray());
}
});
URL url;
try {
url = new URL("http://localhost:8888/manager/text/start?path=/jenkins");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
System.out.println("" + connection.getResponseMessage());
return FormValidation.ok("Success");
} catch (IOException e) {
return FormValidation.error("Client error: " + e.getMessage());
}
}
}
index.jelly inside: resources.org.jenkinsci.plugins.tomcat_app_restart.RestartJksRootAction
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:validateButton
title="${%Restart Jenkins}" progress="${%Restarting...}"
method="JksRestart" with="" />
</j:jelly>
Thank you guys!
I am new to jenkins plugin development, this would help me a lot to understand.
Kind regards.
this demo (rootaction-example-plugin) helped a lot.You can read it.
https://github.com/gustavohenrique/jenkins-plugins/tree/master/rootaction-example-plugin
Add the <l:main-panel> tag and the the <l:layout norefresh="true">tag to the index.jelly file.
And include the side panel:
Pass the the build to Action (through a parameter of the constructor)
The build can be retrieved out of the parameters of the perform method which is inherited from the BuildStepCompatibilityLayer class (by Extending Publisher).
Create a getBuild() method in the Action class
Add the <st:include it="${it.build}" page="sidepanel.jelly" /> tag with the build
Jelly Example (index.jelly):
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<l:layout norefresh="true">
<st:include it="${it.build}" page="sidepanel.jelly" />
<l:main-panel>
<f:validateButton title="${%Restart Jenkins}" progress="${%Restarting...}" method="JksRestart" with="" />
</l:main-panel>
</l:layout>
</j:jelly>
Java Action class example:
package tryPublisher.tryPublisher;
import hudson.model.Action;
import hudson.model.AbstractBuild;
public class ExampleAction implements Action {
AbstractBuild<?,?> build;
public ExampleAction(AbstractBuild<?,?> build) {
this.build = build;
}
#Override
public String getIconFileName() {
return "/plugin/action.png";
}
#Override
public String getDisplayName() {
return "ExampleAction";
}
#Override
public String getUrlName() {
return "ExampleActionUrl";
}
public AbstractBuild<?,?> getBuild() {
return this.build;
}
}
Java Publisher class example:
package tryPublisher.tryPublisher;
import java.io.IOException;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
public class ExamplePublisher extends Publisher {
#Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}
#Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {
build.getActions().add(new ExampleAction(build));
return true;
}
}
The .jelly file has to be in the right resources map of the plugin project. In a map with the same name as the name of the Java class implementing Action. The name of the .jelly is important also.

GXT - ComoboBox with Multi select feature

I have a task to design a control of size ComboBox (GXT) with Multi-select feature. I tried to set CheckBoxListView using setView of ComboBox but did not seemed to work. Can anybody please guide me if there is any way using the GXT framework I can achieve this?
PS: I found a component called XComboBox in sencha forum (java class, source code) which works good, but cant be used as its under GNU GPL License
Thanks in advance!
Thanks #smiletolead for your guidance, I found a solution by integrating Dialog with CheckBoxListView and TriggerField class.
The complete code listing is..
package com.ui.test.client;
import java.util.List;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.WindowEvent;
import com.extjs.gxt.ui.client.event.WindowListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.CheckBoxListView;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.form.TriggerField;
import com.extjs.gxt.ui.client.widget.layout.FillLayout;
import com.google.gwt.user.client.Element;
public class MultiSelectComboBox extends TriggerField {
private Dialog checkBoxListHolder;
private CheckBoxListView listView;
private ListStore store;
private String delimiter = ",";
private boolean readOnly;
public MultiSelectComboBox() {
store = new ListStore();
listView = new CheckBoxListView();
}
#Override
protected void onTriggerClick(ComponentEvent ce) {
super.onTriggerClick(ce);
if(readOnly) {
return;
}
checkBoxListHolder.setSize(getWidth(), 200);
listView.setWidth(getWidth());
checkBoxListHolder.setPosition(getAbsoluteLeft(),
getAbsoluteTop() + getHeight());
if(checkBoxListHolder.isVisible()) {
checkBoxListHolder.hide();
}
else {
checkBoxListHolder.show();
}
}
#Override
protected void onRender(Element target, int index) {
super.onRender(target, index);
checkBoxListHolder = new Dialog();
checkBoxListHolder.setClosable(false);
checkBoxListHolder.setHeaderVisible(false);
checkBoxListHolder.setFooter(false);
checkBoxListHolder.setFrame(false);
checkBoxListHolder.setResizable(false);
checkBoxListHolder.setAutoHide(false);
checkBoxListHolder.getButtonBar().setVisible(false);
checkBoxListHolder.setLayout(new FillLayout());
checkBoxListHolder.add(listView);
listView.setStore(store);
checkBoxListHolder.addWindowListener(new WindowListener(){
#Override
public void windowHide(WindowEvent we) {
setValue(parseCheckedValues(listView));
}
});
}
private String parseCheckedValues(CheckBoxListView checkBoxView) {
StringBuffer buf = new StringBuffer();
if(checkBoxView != null) {
List selected = checkBoxView.getChecked();
int index = 1, len = selected.size();
for(D c : selected) {
buf.append(c.get(listView.getDisplayProperty()));
if(index getListView() {
return listView;
}
public void setListView(CheckBoxListView listView) {
this.listView = listView;
}
public ListStore getStore() {
return store;
}
public void setStore(ListStore store) {
this.store = store;
}
public String getDelimiter() {
return delimiter;
}
public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
}
public boolean isReadOnly() {
return readOnly;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
}
The code has been explained here...
http://bhat86.blogspot.com/2012/02/gxt-comobobox-with-multi-select-feature.html
Thank you!
Refer the examples listview and advanced list view. They may be of some help to you in developing combobox with multi select option