pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brendan cheng <ccp...@hotmail.com>
Subject Use Drag and Drop in TableView Header
Date Thu, 06 Dec 2012 12:44:29 GMT
Hi,
I tried to implement a drag and drop function on column of table view header.  I followed
an example of Demo and coded as followed but nothing happened.  Could you give me some advice
on my code?
Brendan
Here is:		primaryHeader.setDragSource(new DragSource() {


			private LocalManifest content = null;


			@Override
			public boolean beginDrag(Component component, int x, int y) {
				int columnIndex = primaryHeader.getTableView().getColumnAt(x);
				Column column = primaryHeader.getTableView()
						.getColumns().get(columnIndex);
				if (column != null) {
					content = new LocalManifest();
					dragDropKey = column.getName();
					content.putValue(dragDropKey, column);
				}


				return (content != null);
			}


			@Override
			public void endDrag(Component component, DropAction dropAction) {
				content = null;


			}


			@Override
			public boolean isNative() {
				return true;
			}


			@Override
			public LocalManifest getContent() {
				return content;
			}


			@Override
			public Visual getRepresentation() {
				// TODO Auto-generated method stub
				return null;
			}


			@Override
			public Point getOffset() {
				// TODO Auto-generated method stub
				return null;
			}


			@Override
			public int getSupportedDropActions() {
				return DropAction.COPY.getMask();
			}
		});


		primaryHeader.setDropTarget(new DropTarget() {
			@Override
			public DropAction dragEnter(Component component,
					Manifest dragContent, int supportedDropActions,
					DropAction userDropAction) {
				DropAction dropAction = null;


				if (dragContent.containsValue(dragDropKey)
						&& DropAction.COPY.isSelected(supportedDropActions)) {
					dropAction = DropAction.COPY;
				}


				return dropAction;
			}


			@Override
			public void dragExit(Component component) {
				// empty block
			}


			@Override
			public DropAction dragMove(Component component,
					Manifest dragContent, int supportedDropActions, int x,
					int y, DropAction userDropAction) {
				return (dragContent.containsValue(dragDropKey) ? DropAction.COPY : null);
			}


			@Override
			public DropAction userDropActionChange(Component component,
					Manifest dragContent, int supportedDropActions, int x,
					int y, DropAction userDropAction) {
				return (dragContent.containsValue(dragDropKey) ? DropAction.COPY : null);
			}


			@Override
			public DropAction drop(Component component, Manifest dragContent,
					int supportedDropActions, int x, int y,
					DropAction userDropAction) {
				DropAction dropAction = null;
				int columnIndex = primaryHeader.getTableView().getColumnAt(x);
				if (dragContent.containsValue(dragDropKey)) {
					try {
						primaryHeader
								.getTableView()
								.getColumnSource()
								.getColumns()
								.remove((Column) dragContent
										.getValue(dragDropKey));
						primaryHeader
								.getTableView()
								.getColumnSource()
								.getColumns()
								.insert((Column) dragContent
										.getValue(dragDropKey), columnIndex);
						dropAction = DropAction.COPY;
					} catch (IOException exception) {
						System.err.println(exception);
					}
				}


				dragExit(component);


				return dropAction;
			}
		});
 		 	   		  
Mime
View raw message