import java.io.IOException;
import org.eclipse.swt.dnd.ByteArrayTransfer;
-import org.tizen.common.util.log.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.tizen.sdblib.service.FileEntry;
public class FileEntryTransfer extends ByteArrayTransfer {
+ protected final Logger logger = LoggerFactory.getLogger(getClass());
- private static FileEntryTransfer instance = new FileEntryTransfer();
- private static final String TYPE_NAME = "sdb-transfer-format";
- private static final int TYPE_ID = registerType(TYPE_NAME);
+ private static FileEntryTransfer instance = new FileEntryTransfer();
+ private static final String TYPE_NAME = "sdb-transfer-format";
+ private static final int TYPE_ID = registerType(TYPE_NAME);
- private FileEntryTransfer() { }
-
- public static FileEntryTransfer getInstance() {
- return instance;
- }
- @Override
- protected int[] getTypeIds() {
- return new int[] { TYPE_ID };
- }
- @Override
- protected String[] getTypeNames() {
- return new String[] { TYPE_NAME };
- }
-
- public byte[] toByteArray(FileEntry[] entries) {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream(byteOut);
+ private FileEntryTransfer() {
+ }
- byte[] bytes = null;
+ public static FileEntryTransfer getInstance() {
+ return instance;
+ }
- try {
- out.writeInt(entries.length);
+ @Override
+ protected int[] getTypeIds() {
+ return new int[] { TYPE_ID };
+ }
- for (int i = 0; i < entries.length; i++) {
- FileEntry data = entries[i];
- if (data instanceof FileEntry) {
- try {
- out.writeUTF(((FileEntry) data).getFullPath());
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
+ @Override
+ protected String[] getTypeNames() {
+ return new String[] { TYPE_NAME };
+ }
- out.close();
- bytes = byteOut.toByteArray();
- } catch (IOException e) {
- // when in doubt send nothing
- Logger.error("write utf failed:" + e);
- }
- return bytes;
- }
+ public byte[] toByteArray(FileEntry[] entries) {
+ ByteArrayOutputStream byteOut = null;
+ DataOutputStream out = null;
+ byte[] bytes = null;
+ try {
+ byteOut = new ByteArrayOutputStream();
+ out = new DataOutputStream(byteOut);
+ out.writeInt(entries.length);
+ for (int i = 0; i < entries.length; i++) {
+ FileEntry data = entries[i];
+ try {
+ out.writeUTF(((FileEntry) data).getFullPath());
+ } catch (IOException e1) {
+ logger.error("Failed to write", e1);
+ }
+ }
+ bytes = byteOut.toByteArray();
+ } catch (IOException e) {
+ // when in doubt send nothing
+ logger.error("Failed to write", e);
+ } finally {
+ if (out != null)
+ try {
+ out.close();
+ } catch (IOException e) {
+ }
+ }
+ return bytes;
+ }
- public String[] fromByteArray(byte[] bytes) {
- DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
- try {
- int n = in.readInt();
-
- String[] paths = new String[n];
- for (int i = 0; i < n; i++) {
- String path = in.readUTF();
- paths[i] = path;
- }
- return paths;
- } catch (IOException e) {
- Logger.error("read integer failed:" + e);
- return null;
- }
- }
-
-
+ public String[] fromByteArray(byte[] bytes) {
+ DataInputStream in = null;
+ try {
+ in = new DataInputStream(new ByteArrayInputStream(bytes));
+ int n = in.readInt();
+ String[] paths = new String[n];
+ for (int i = 0; i < n; i++) {
+ String path = in.readUTF();
+ paths[i] = path;
+ }
+ return paths;
+ } catch (IOException e) {
+ logger.error("Failed to read an int", e);
+ return null;
+ } finally {
+ if (in != null)
+ try {
+ in.close();
+ } catch (IOException e) {
+ }
+ }
+ }
}
GomMessages.SMARTLAUNCH_CYCLE_COLUMNS_4};
private String[] sampleColumns = {"Profile", "ProjectProject", "LaunchConfigurationLaunchConfiguration", "emulator-xxxxx"};
- private final static String TIZEN_SMART_LAUNCH_UP_ID="org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.up";
- private final static String TIZEN_SMART_LAUNCH_DOWN_ID="org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.down";
+ private final static String TIZEN_SMART_LAUNCH_UP_ID = "org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.up";
+ private final static String TIZEN_SMART_LAUNCH_DOWN_ID = "org.tizen.common.gom.smartlaunch.ui.tizensmartlauncher.down";
@Override
protected void addItems(Table table, WorkbenchPage page) {
.getWorkbench().getService(ICommandService.class);
final Command command = commandService
.getCommand(TIZEN_SMART_LAUNCH_UP_ID);
- ParameterizedCommand commandBack = new ParameterizedCommand(command,
- null);
+ ParameterizedCommand commandBack = new ParameterizedCommand(command, null);
return commandBack;
}
table.setHeaderVisible(true);
table.setLinesVisible(true);
- for(int i = 0 ;i < columns.length ; i++)
- {
+ for (int i = 0 ;i < columns.length ; i++) {
createTableColumn(table, sampleColumns[i], columns[i]);
}
addItems(table, page);
int tableItemCount = table.getItemCount();
-
switch (tableItemCount) {
case 0:
cancel(dialog);
default:
int i;
if (gotoDirection) {
- i= getCurrentItemIndex() + 1;
+ i = getCurrentItemIndex() + 1;
if (i >= tableItemCount)
- i= 0;
+ i = 0;
} else {
- i= getCurrentItemIndex() - 1;
+ i = getCurrentItemIndex() - 1;
if (i < 0)
- i= tableItemCount - 1;
+ i = tableItemCount - 1;
}
table.setSelection(i);
}
dialog.pack();
Rectangle tableBounds = table.getBounds();
- tableBounds.height = Math.min(tableBounds.height, table.getItemHeight()
- * MAX_ITEMS);
+ tableBounds.height = Math.min(tableBounds.height, table.getItemHeight() * MAX_ITEMS);
table.setBounds(tableBounds);
- dialog.setBounds(dialog.computeTrim(tableBounds.x, tableBounds.y,
- tableBounds.width, tableBounds.height));
+ dialog.setBounds(dialog.computeTrim(tableBounds.x, tableBounds.y, tableBounds.width, tableBounds.height));
table.setFocus();
table.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
- // Do nothing
}
public void focusLost(FocusEvent e) {
public void mouseMove(MouseEvent e) {
if (table.equals(e.getSource())) {
- Object o = table.getItem(new Point(e.x, e.y));
+ TableItem o = table.getItem(new Point(e.x, e.y));
if (lastItem == null ^ o == null) {
- table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(
- SWT.CURSOR_HAND));
+ table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
}
- if (o instanceof TableItem) {
+ if (o == null) {
+ lastItem = null;
+ } else {
if (!o.equals(lastItem)) {
- lastItem = (TableItem) o;
+ lastItem = o;
table.setSelection(new TableItem[] { lastItem });
}
- } else if (o == null) {
- lastItem = null;
}
}
}
}
}
- private TableColumn createTableColumn(Table table, String sampleText, String text)
- {
+ private TableColumn createTableColumn(Table table, String sampleText, String text) {
TableColumn tc = new TableColumn(table, SWT.NONE);
tc.setResizable(true);
tc.setText(sampleText);
@Override
protected void activate(IWorkbenchPage page, Object selectedItem) {
- if (page == null) {
- return;
- }
-
- if (selectedItem == null) {
+ if (page == null || selectedItem == null) {
return;
}
GomSmartLauncher.smartLaunch(data);
}
}
-
}
}