o:graphicImage with dataURI="true" frozen programm via update - omnifaces

I have the following code.
The remoteCommand is executing after 5 seconds the method and update the h:form.
<h:form>
<p:remoteCommand name="checkPageRc" autoRun="true"
resetValues="true" async="false"
delay="5000"
actionListener="#{previewPhotoboothProfileController.doLoadCurrentPage(previewPhotoboothProfileController.selectedPhotoboothPage)}" />
</h:form>
<h:form id="previewPageForm">
<o:graphicImage dataURI="true"
rendered="#{previewPhotoboothProfileController.photoboothTemplate.photoboothCurrentSession.singlePictureOutput != null}"
value="#{storageOutputHelperController.loadImageByByteArray(previewPhotoboothProfileController.photoboothTemplate.photoboothCurrentSession.singlePictureOutput)}"
cache="false" />
</h:form>
My backend bean:
#GraphicImageBean
public class StorageOutputHelperController implements Serializable {
public byte[] loadImageByByteArray(byte[] bytes) throws IOException {
LOGGER.info("START loadImageByByteArray");
try {
// Falls Null
if (bytes == null)
return Utils.toByteArray(Faces.getResourceAsStream("/resources/images/no-photo-icon.png"));
LOGGER.info("END loadImageByByteArray");
return bytes;
} catch (Exception e) {
LOGGER.error(ExceptionUtils.getFullStackTrace(e));
return Utils.toByteArray(Faces.getResourceAsStream("/resources/images/no-photo-icon.png"));
}
}
}
previewPhotoboothProfileController.photoboothTemplate.photoboothCurrentSession.singlePictureOutput is already a byte array.
The problem is now, that the o:graphicImage will be updated, but only after 10 seconds and it the programm / thread is frozen.
It seems that the update from the p:remoteCommand for the h:form is the issue.
If I´m using <o:graphicImage dataURI="false" I cannot see this behaviour from the frozen window / programm but than the image is not showing.
Is this a known issue or is there something wrong from my end?
Edit:
Ok, it seems like the issue is in my SWT Browser screen which I open like this:
Display.getDefault().asyncExec(new Runnable() {
public void run() {
Display display = Display.getCurrent();
final Shell shell = new Shell(display);
Rectangle clientArea = Display.getCurrent().getClientArea();
shell.addListener(SWT.Traverse, new Listener() {
#Override
public void handleEvent(Event event) {
if (event.character == SWT.ESC) {
event.doit = false;
shell.close();
}
}
});
shell.setSize(500, 500);
shell.setFullScreen(false);
shell.setLocation(0, 0);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 3;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
shell.setLayout(gridLayout);
final Browser browser = new Browser(shell, SWT.NONE);
browser.setJavascriptEnabled(true);
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.horizontalSpan = 3;
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
data.widthHint = clientArea.width;
data.heightHint = clientArea.height;
browser.setLayoutData(data);
shell.open();
browser.setUrl("http://localhost:" + Constants.SERVER_PORT
+ "/portal/myurl);
}
});
Any idea, why the program is frozen?
If I check this in my local browser, it seems it´s working fine

Related

Activity closing unexpectedly after pressing back button

I'm currently trying to diagnosis a bug where when a user is wanting to back out of the game activity using the back button it closes the window but doesn't seem to actually close the activity. The reason I think the activity isn't closing is because when a new game activity is started, the activity seems to call onFinish from CountDownTimer and close as if the time ran out when the timer in game shows there is still time left in the new game. Essentially I think my old activity is closing my new activity, even after the activity is no longer showing and should be closed based on my onBackPressed() method.
Here is my code:
public class Game extends Activity {
ImageButton position0;
ImageButton position1;
ImageButton position2;
ImageButton position3;
Button colorPosition;
RelativeLayout background;
Random rand = new Random();
int[] position = {0,1,2,3};
int score = 0;
int streak = 1;
int multi = 1;
int currentColor;
SharedPreferences gamePrefs;
boolean countDisable = true;
public static final String GAME_PREFS = "ColorMatchFile";
TextView scoreText;
TextView multiplierText;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
gamePrefs = getSharedPreferences(GAME_PREFS, 0);
scoreText = (TextView) findViewById(R.id.score);
multiplierText= (TextView) findViewById(R.id.multiplier);
background = (RelativeLayout) findViewById(R.id.background);
StartCount start_count = new StartCount(5000, 1000);
start_count.start();
colorPosition = (Button)findViewById(R.id.colorPosition);
position0 = (ImageButton)findViewById(R.id.position0);
position1 = (ImageButton)findViewById(R.id.position1);
position2 = (ImageButton)findViewById(R.id.position2);
position3 = (ImageButton)findViewById(R.id.position3);
if(savedInstanceState != null){
int exScore = savedInstanceState.getInt("score");
scoreText.setText("Score: "+ exScore);
}
#Override
public void onBackPressed() {
setHighScore();
finish();
Intent intent = new Intent(getApplicationContext(), score_screen.class);
startActivity(intent);
super.onBackPressed();
}
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture,long countDownInterval){
super(millisInFuture, countDownInterval);
}
#Override
public void onFinish() {
final TextView time = (TextView) findViewById(R.id.time);
time.setText("Times Up!");
Thread thread = new Thread();
try {
thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
setHighScore();
finish();
Intent intent = new Intent(getApplicationContext(), score_screen.class);
startActivity(intent);
}
#Override
public void onTick(long millisUntilFinished){
final TextView time = (TextView) findViewById(R.id.time);
time.setText("Left: " + millisUntilFinished/1000);
}
}
public class StartCount extends CountDownTimer{
public StartCount(long millisInFuture,long countDownInterval){
super(millisInFuture, countDownInterval);
}
#Override
public void onFinish() {
final TextView time = (TextView) findViewById(R.id.time);
time.setText("Begin!");
MyCount counter = new MyCount(30000, 1000);
currentColor = rand.nextInt(4);
setCurrentColor(currentColor);
countDisable = false;
counter.start();
}
#Override
public void onTick(long millisUntilFinished){
final TextView time = (TextView) findViewById(R.id.time);
time.setText("Start In: " + millisUntilFinished/1000);
showCurrentPosition();
}
}
Well the problem was I wasn't turning the counter for MyCount off. Here is how I solved it:
#Override
public void onBackPressed() {
setHighScore();
counter.cancel();
this.finish();
Intent intent = new Intent(getApplicationContext(), score_screen.class);
startActivity(intent);
}
Note I had to use counter.cancel() and make counter a global variable.

Gwt CheckBoxCell check uncheck issue

I am not able to check or uncheck a Gwt CheckBoxCell . It works fine in Chrome but it doesn't work at all in mozilla . What wrong i am doing ? Please Suggest . When i am selecting selectAllHeader not able to check/uncheck in mozilla though same works in chrome.
DataGridTableRowModel headerRow = dataGridTableRowList.get(0);
E12CommonUtils.printOnConsole("IN createTableComponent================="+ headerRow);
int width = 50;
final MultiSelectionModel<DataGridTableRowModel> multiSelectionModel = new MultiSelectionModel<DataGridTableRowModel>();
this.setSelectionModel(multiSelectionModel,DefaultSelectionEventManager.<DataGridTableRowModel> createCheckboxManager(0));
multiSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler()
{
public void onSelectionChange(SelectionChangeEvent event)
{
count++;
E12CommonUtils.printOnConsole("Inside select : ");
Set<DataGridTableRowModel> set = multiSelectionModel.getSelectedSet();
Iterator it = set.iterator();
selectedValues = new StringBuffer();
selectedNames = new StringBuffer();
while (it.hasNext())
{
DataGridTableRowModel row = (DataGridTableRowModel) it.next();
E12CommonUtils.printOnConsole("Inside select = "+ row.getCellText(1));
selectedValues.append(row.getCellText(1) + ":");
E12CommonUtils.printOnConsole("AFTER APPENDING selectedValues = "+ row.getCellText(1));
selectedNames.append(row.getCellData(1).getName() + ":");
}
}
});
E12CommonUtils.printOnConsole("IN $$$$$$$$$$$$$$$$$=================135");
final Column<DataGridTableRowModel, Boolean> checkColumn = new Column<DataGridTableRowModel, Boolean>(new E12CheckBoxCell(false, false))
{
#Override
public Boolean getValue(DataGridTableRowModel dataGridTRModel)
{
boolean isSelected = multiSelectionModel.isSelected(dataGridTRModel);
E12CommonUtils.printOnConsole("checkColumn isSelected["+ isSelected + "]\tprotect["+ dataGridTRModel.getCellData(0).isProtect() + "]");
getFieldUpdater().update(0, dataGridTRModel, isSelected); // If commented deselect all works
return isSelected;
}
};
checkColumn.setFieldUpdater(new FieldUpdater<DataGridTableRowModel, Boolean>()
{
#Override
public void update(int idx,DataGridTableRowModel dataGridTRModel,Boolean value)
{
try
{
CellData cellData = dataGridTRModel.getCellData(0);
cellData.setData(String.valueOf(value));
dataGridTRModel.setCellData(0, cellData);
multiSelectionModel.setSelected(dataGridTRModel, value);
}
catch (Exception e)
{
Window.alert("Exception in checkColumn.setFieldUpdater : "+ e.getMessage());
}
}
});
CheckboxCell checkAll = new CheckboxCell();
// E12CheckBoxCell checkAll = new E12CheckBoxCell(false, false);
Header<Boolean> selectAllHeader = new Header<Boolean>(checkAll){
#Override
public Boolean getValue()
{
E12CommonUtils.printOnConsole("IN getValue()=========");
return false;
}
};
selectAllHeader.setUpdater(new ValueUpdater<Boolean>(){
#Override
public void update(Boolean selected)
{
for (DataGridTableRowModel ele : getVisibleItems())
{
E12CommonUtils.printOnConsole("IN update**************");
multiSelectionModel.setSelected(ele, selected);
}
}
});
this.addColumn(checkColumn, selectAllHeader);
this.setColumnWidth(checkColumn, 20, Unit.PX);
for (int i = 1; i < headerRow.getRowData().size(); i++)
{
final int index = i;
final String colName = headerRow.getCellData(index).getName();
width = 25;// TODO
E12CustomColumn column = new E12CustomColumn(index, false);
this.setColumnWidth(column, width + "px");
// Add a selection model to handle user selection.
ResizableHeader<DataGridTableRowModel> header = new ResizableHeader<DataGridTableRowModel>(colName, this, column) {
#Override
public String getValue()
{
return colName;
}
};
// this.addColumn(column, selectAllHeader,header);
// this.addColumn(selectAllHeader, header);
this.addColumn(column, header);
}
dataProvider.addDataDisplay(this);
dataProvider.refresh();
it may be browser compatibility issue - meta tag might help you
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
For more details follow below url -
What does <meta http-equiv="X-UA-Compatible" content="IE=edge"> do?

Issue with JFrame, opens blank

For a project of mine (I'm very new & even newer to guis) I'm making a GUI based game it has worked so far however, when you complete level one, it reopens level two but the JFrame is completely white and unresponsive, I have tried a few things but however I am not close to finding out what the issue is. Please help me, The code for the game is:
public class gameWithGuis extends JFrame implements ActionListener, Runnable{
static int levelNum = 1;
static int find;
static int length = 3;
static int area = length * length;
static ArrayList<JButton> buttonsHolder = new ArrayList<JButton>();
Container pane = getContentPane();
static gameWithGuis threadA = new gameWithGuis(); //Starts 10 second timer
static Thread timerThread = new Thread(threadA);
static boolean levelUp = false;
public void run(){
try{
int time = 1;
while (time<=10){
Thread.sleep(1000);
time++;
}
super.dispose();
JOptionPane.showMessageDialog(null,"You have ran out of time! Game over!");
highscores(levelNum);
}catch (Exception e){}
}
public void main(){
Scanner sc = new Scanner(System.in);
JOptionPane.showMessageDialog(null,"Welcome to pseudo-Where's Wally, look for the lower case L(l) character.");
JOptionPane.showMessageDialog(null,"You get 10 seconds to find it.");
JOptionPane.showMessageDialog(null,"The answer are the coordinates multiplied together.");
JOptionPane.showMessageDialog(null,"That is what you must type in. Good luck!");
JOptionPane.showMessageDialog(null,"Ready?..");
char clear = (char)(12);
System.out.print(clear);
timerThread.start();
makingGrid();
}
public static void highscores(int levelNum){
AQAWriteTextFile2013 writer = new AQAWriteTextFile2013();
AQAReadTextFile2013 reader = new AQAReadTextFile2013();
Scanner scTwo = new Scanner(System.in);
String fileName = "highscores.txt";
String save = JOptionPane.showInputDialog(null,"Would you like to save your score? (yes or no): ");
if (save.equalsIgnoreCase("yes")){
String runningLine = "";
String name = JOptionPane.showInputDialog(null,"Name please: ");
writer.openFile(fileName, true); //opens highscore file
String writeLine = name + "\t" + levelNum;
writer.writeToTextFile(writeLine); //writes your name and the level you reached to the file
writer.closeFile();
reader.openTextFile(fileName); //shows you the list of peoples scores
JOptionPane.showMessageDialog(null,"Current Highscores: ");
String line = reader.readLine();
if (line ==null) JOptionPane.showMessageDialog(null,"- - NONE - -"); //if file is empty
do //prints the lines within the file
{
line = reader.readLine();
runningLine = runningLine+"\n"+line+" ";
}while (line !=null);
JOptionPane.showMessageDialog(null,runningLine);
reader.closeFile();
System.exit(0);
} else if (save.equalsIgnoreCase("no")){
JOptionPane.showMessageDialog(null,"Okay, thank you for playing!");
System.exit(0);
} else {
JOptionPane.showMessageDialog(null,"Please answer yes or no."); //validation
}
}
public static void main(String[] args) throws Exception{
new gameWithGuis().main();
}
#Override
public void actionPerformed(ActionEvent arg0){
JButton[] buttons = buttonsHolder.toArray(new JButton[buttonsHolder.size()]);
// for(int i = 0; i<=amountOfButtons; i++){
// buttonsHolder[].toArray();
// // buttons[i] = buttonsHolder[i];
// }
if(arg0.getSource().equals(buttons[find])){
timerThread.stop();
JOptionPane.showMessageDialog(null,"Correct!");
levelNum++;
JOptionPane.showMessageDialog(null,"Level up! You are now on level: "+levelNum+". The grid has an area of "+(length*length)+" now.");
levelUp = true; //go through to the next level
pane.removeAll();
super.dispose();
makingGrid();
}else{
timerThread.stop();
JOptionPane.showMessageDialog(null,"You guessed wrong! Game over!");
JOptionPane.showMessageDialog(null,"You reached level: "+levelNum+".");
highscores(levelNum);
}
}
public void makingGrid(){
do{
if(levelNum>1){
length = length + 2; //increase length and height of box by 2 both ways
area = length*length;
}
JButton[] buttons = new JButton[area];
Random gen = new Random();
find = gen.nextInt(area);
setTitle("Where's J?");
// Container pane = getContentPane();
pane.setLayout(new GridLayout(length, length));
for(int i = 0; i<area; i++){
buttons[i] = new JButton();
buttons[i].setText("I");
if(i == find){
buttons[i].setText("J");
}
buttonsHolder.add(buttons[i]);
pane.add(buttons[i]);
buttons[i].addActionListener(this);
}
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// timerThread.start();
} while (levelUp);
}
}
Please no sarcastic comments if I'm being stupid and missed something obvious too you, I'm new too this language and to this website. Thanks for any help.
don't worry... No one will give you a sarcastic comment. It is just not right or fair.
Your code has a lot to improve. But congratulations for writing it!
Your problem is that levelUp is always true on the second level. This causes an infinite loop inside the makingGrid(). In this case JFrame stop repainting.

Drag and drop to other applications and OS?

I'm using JavaFX's Drag and Drop system in my application, and it has been working well so far.
Now I want to support drag and drop to outside applications, eg. dragging files from my application to the explorer. How would I achieve that?
I've achieved what you described by using:
Vector<File> files = new Vector<File>();
private ClipboardContent filesToCopyClipboard = new ClipboardContent();
...
final ObjectWithAReturnablePathField draggableObj = new ObjectWithAReturnablePathField();
...
draggableObj.setOnDragDetected(new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent me)
{
Dragboard db = draggableObj.startDragAndDrop(TransferMode.ANY);
try
{
File f = new File(new URI(draggableObj.getFilePath()));
files.add(f);
filesToCopyClipboard.putFiles(files);
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
db.setContent(filesToCopyClipboard);
me.consume();
}
});
draggableObj.setOnDragDone(new EventHandler<DragEvent>()
{
#Override
public void handle(DragEvent me)
{
me.consume();
}
});
Which means:
It's possible to achieve file transference between JavaFX 2 and a native application by filling a ClipboardContent with a list using the TransferMode.ANY on the setOnDragDetected method of any Draggable Object (Any Node) which can return a Path for a file. In my case, I've created a class called Thumb extending ImageView and (among others things) I made a method called getFilePath() which returns the Path from the Image used to initialize the ImageView(). I'm sorry BTW for the poor example and the poor english, but I'm running out of time to give a more detailed answer as of now. I hope it helps. Cheers
Here is a sample source for an action listener on an ImageView image extraction to OS' explorer (With a custom process for jpg image to remove alpha-channel to display it correctly):
inputImageView.setOnDragDetected(new EventHandler <MouseEvent>() {
#Override
public void handle(MouseEvent event) {
// for paste as file, e.g. in Windows Explorer
try {
Clipboard clipboard Clipboard.getSystemClipboard();
Dragboard db = inputImageView.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
Image sourceImage = inputImageView.getImage();
ImageInfo imageInfo = (ImageInfo) inputImageView.getUserData();
String name = FilenameUtils.getBaseName(imageInfo.getName());
String ext = FilenameUtils.getExtension(imageInfo.getName());
///Avoid get "prefix lenght too short" error when file name lenght <= 3
if (name.length() < 4){
name = name+Long.toHexString(Double.doubleToLongBits(Math.random()));;
}
File temp = File.createTempFile(name, "."+ext);
if (ext.contentEquals("jpg")|| ext.contentEquals("jpeg")){
BufferedImage image = SwingFXUtils.fromFXImage(sourceImage, null); // Get buffered image.
BufferedImage imageRGB = new BufferedImage(image.getWidth(),image.getHeight(),
BufferedImage.OPAQUE);
Graphics2D graphics = imageRGB.createGraphics();
graphics.drawImage(image, 0, 0, null);
ImageIO.write(imageRGB, ext, temp);
graphics.dispose();
ImageIO.write(imageRGB,
ext, temp);
}else{
ImageIO.write(SwingFXUtils.fromFXImage(sourceImage, null),
ext, temp);
}
content.putFiles(java.util.Collections.singletonList(temp));
db.setContent(content);
clipboard.setContent(content);
event.consume();
temp.deleteOnExit();
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
});
With the help of use of an Object that is passed to the imageView's setUserData method, it helps me to retrieve database id and pic name:
public class ImageInfo {
private String imageInfo;
private int inputId;
#Override
public String toString() {
return imageInfo;
}
public ImageInfo(String imageInfo, int inputId) {
this.imageInfo = imageInfo;
this.inputId = inputId;
}
public String getName() {
return imageInfo;
}
public void setName(String imageInfo) {
this.imageInfo = imageInfo;
}
public int getIndex() {
return inputId;
}
public void setIndex(int areaindex) {
this.inputId = inputId;
}
}
I hope it will help somenone at an expected time :-)
Regards

Problem with GWT connector in a straight ended connection

I am trying to make a straight ended connection between widgets.But when I am doing so, the orientation of my connector is coming wrong.Its always coming parallel to the required one.Also , it is independent of the connecting widgets i.e when I move my widget, my connector does not move.Snippet of my code is given as :
Link to snapshot of the problem: http://goo.gl/JUEmJ
public class DragNDropPage {
SyncCurrentUser cu = SyncCurrentUser.getUser();
private AbsolutePanel area = new AbsolutePanel();
HorizontalPanel toolsPanel = new HorizontalPanel();
AbsolutePanel canvas = new AbsolutePanel();
DragController toolboxDragController;
Label startLabel = new Label("START");
Label stopLabel = new Label("STOP");
Label activityLabel = new Label("ACTIVITY");
Label processLabel = new Label("PROCESS");
Button stopDrag = new Button("Done Dragging");
Button saveButton = new Button("Save");
PickupDragController dragController = new PickupDragController(area, true);
AbsolutePositionDropController dropController = new AbsolutePositionDropController(area);
private List<Widget> selected = new ArrayList<Widget>();
private List<Widget> onCanvas = new ArrayList<Widget>();
private List<Connection> connections = new ArrayList<Connection>();
private CActivity[] aItems;
private CProcess[] pItems;
MyHandler handler = new MyHandler();
int mouseX,mouseY;
String style;
public DragNDropPage() {
toolboxDragController = new ToolboxDragController(dropController, dragController);
RootPanel.get("rightbar").add(area);
area.setSize("575px", "461px");
area.add(toolsPanel);
toolsPanel.setSize("575px", "37px");
toolsPanel.add(startLabel);
startLabel.setSize("76px", "37px");
toolboxDragController.makeDraggable(startLabel);
toolsPanel.add(stopLabel);
stopLabel.setSize("66px", "37px");
toolboxDragController.makeDraggable(stopLabel);
toolsPanel.add(activityLabel);
activityLabel.setSize("82px", "36px");
toolboxDragController.makeDraggable(activityLabel);
toolsPanel.add(processLabel);
processLabel.setSize("85px", "36px");
toolboxDragController.makeDraggable(processLabel);
stopDrag.addClickHandler(handler);
toolsPanel.add(stopDrag);
stopDrag.setWidth("114px");
saveButton.addClickHandler(handler);
toolsPanel.add(saveButton);
area.add(canvas, 0, 36);
canvas.setSize("575px", "425px");
Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
//46 is the key code for Delete Button
if(event.getNativeEvent().getKeyCode() == 46 && !selected.isEmpty()) {
for (Iterator<Widget> i = selected.listIterator(); i.hasNext();) {
Widget w = (Widget) i.next();
UIObjectConnector.unwrap(w);
i.remove();
w.removeFromParent();
onCanvas.remove(i);
}
}
}
});
aItems = cu.currentUser.getcActivity();
pItems = cu.currentUser.getcProcess();
}
private class ToolboxDragController extends PickupDragController {
public ToolboxDragController(final DropController dropController, final DragController nodesDragController) {
super(area ,false);
setBehaviorDragProxy(true);
registerDropController(dropController);
addDragHandler(new DragHandlerAdapter(){
public void onPreviewDragEnd(DragEndEvent event) throws VetoDragException {
Widget node = (Widget) event.getSource();
int left = event.getContext().desiredDraggableX;
int top = event.getContext().desiredDraggableY;
AbsolutePanel panel = (AbsolutePanel) dropController.getDropTarget();
createConnector((Label) node, panel, left, top);
throw new VetoDragException();
}
});
}
}
protected UIObjectConnector createConnector(Label proxy, AbsolutePanel panel, int left, int top) {
Widget w;
String str = proxy.getText();
if(str.equals("START") || str.equals("STOP")){
w = new Label(proxy.getText()){
public void onBrowserEvent(Event event) {
if( DOM.eventGetType(event) == 4
&& DOM.eventGetCtrlKey(event)){
select(this);
}
super.onBrowserEvent(event);
}
};
w.getElement().setClassName("dnd-start-stop");
}
else{
w = new ListBox(){
public void onBrowserEvent(Event event) {
if( DOM.eventGetType(event) == 4
&& DOM.eventGetCtrlKey(event)){
select(this);
}
super.onBrowserEvent(event);
}
};
if(str.equals("ACTIVITY")){
getAItems((ListBox)w);
//w.getElement().addClassName("dnd-activity");
}
else if(str.equals("PROCESS")){
getPItems((ListBox)w);
//w.getElement().addClassName("dnd-process");
}
}
onCanvas.add(w);
left -= panel.getAbsoluteLeft();
top -= panel.getAbsoluteTop();
//panel.add(w,10,10);
panel.add(w, left, top);
dragController.makeDraggable(w);
return UIObjectConnector.wrap(w);
}
private void getAItems(ListBox w) {
for(int i=0;i<aItems.length;i++)
w.addItem(aItems[i].getActivityName());
}
private void getPItems(ListBox w) {
/*for(int i=0;i<pItems.length;i++)
w.addItem(pItems[i].getProcessName());*/
w.addItem("Process1");
}
protected void select(Widget w){
if(selected.isEmpty()) {
selected.add(w);
w.getElement().addClassName("color-green");
} else if(selected.contains(w)){
selected.remove(w);
w.getElement().removeClassName("color-green");
} else if(selected.size() == 1) {
Widget w2 = (Widget) selected.get(0);
connect(UIObjectConnector.getWrapper(w2), UIObjectConnector.getWrapper(w));
selected.clear();
}
}
protected void connect(Connector a, Connector b) {
//System.out.println(a.getLeft());
//System.out.println(b.getLeft());
add(new StraightTwoEndedConnection(a,b));
}
private void add(StraightTwoEndedConnection c) {
canvas.add(c);
connections.add(c);
c.update();
}
protected void remove(Connection c) {
connections.remove(c);
}
class MyHandler implements ClickHandler{
#Override
public void onClick(ClickEvent event) {
Button name = (Button) event.getSource();
if(name.equals(stopDrag)){
if(name.getText().equals("Done Dragging")){
for(Iterator<Widget> i = onCanvas.listIterator();i.hasNext();){
Widget w = (Widget) i.next();
dragController.makeNotDraggable(w);
}
name.setText("Continue");
}
else {
for(Iterator<Widget> i = onCanvas.listIterator();i.hasNext();){
Widget w = (Widget) i.next();
dragController.makeDraggable(w);
}
name.setText("Done Dragging");
}
}
else{
}
}
}
}
I know this is quite old, but I was having similar issues with the gwt-connector library.
The connectors will not appear in the correct placement if you are using standards mode. Use quirks mode instead.
Additionally, you need to manually perform a connector.update() while your dnd components are being dragged (in your drag listener) for the connection to move with the endpoint while you are dragging.