Commit c40b56dc authored by Elemer Lelik's avatar Elemer Lelik
Browse files

Merge pull request #14 from alovassy/master

artf707902 and artf707903: ItemTransfer classes for: include, define
parents 9af52031 4172e7d9
package org.eclipse.titan.designer.editors.configeditor;
import org.antlr.v4.runtime.tree.ParseTree;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.eclipse.titan.common.parsers.cfg.ConfigTreeNodeUtilities;
/**
* Base class for ...ItemTransfer classes,
* they are responsible for handling drag and drop of config editor tab items.
* @author Arpad Lovassy
*/
public abstract class ConfigItemTransferBase extends ByteArrayTransfer {
/**
* Converts parse tree to its string representation. Used by javaToNative().
* @param aRoot parse tree root to convert
* @return the converted string representation of the parse tree
*/
protected String convertToString( final ParseTree aRoot ) {
//TODO: get tokenStream, and use this instead
/*
final StringBuilder sb = new StringBuilder();
// it prints also the hidden token before
ConfigTreeNodeUtilities.print( aRoot, getTokenStream(), sb, null );
return sb.toString();
/*/
return aRoot.getText();
//*/
}
}
......@@ -13,19 +13,21 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.parsers.CommonHiddenStreamToken;
import org.eclipse.titan.common.parsers.LocationAST;
import org.eclipse.titan.common.parsers.AddedParseTree;
import org.eclipse.titan.common.parsers.cfg.ConfigTreeNodeUtilities;
import org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler;
import org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition;
import org.eclipse.titan.designer.editors.configeditor.ConfigItemTransferBase;
/**
* @author Kristof Szabados
* */
public final class DefineItemTransfer extends ByteArrayTransfer {
* @author Arpad Lovassy
*/
public final class DefineItemTransfer extends ConfigItemTransferBase {
private static DefineItemTransfer instance = new DefineItemTransfer();
private static final String TYPE_NAME = "TITAN-DefineSectionItem-transfer-format";
private static final int TYPEID = registerType(TYPE_NAME);
......@@ -56,13 +58,7 @@ public final class DefineItemTransfer extends ByteArrayTransfer {
out.writeInt(items.length);
for (int i = 0; i < items.length; i++) {
out.writeUTF(ConfigTreeNodeUtilities.getHiddenBefore(items[i].getDefinitionName()));
out.writeUTF(items[i].getDefinitionName().getText());
out.writeUTF(ConfigTreeNodeUtilities.getHiddenBefore(items[i].getDefinitionName().getNextSibling()));
out.writeUTF(ConfigTreeNodeUtilities.getHiddenBefore(items[i].getDefinitionValue()));
out.writeUTF(items[i].getDefinitionValue().getText());
out.writeUTF( convertToString( items[i].getRoot() ) );
}
out.close();
bytes = byteOut.toByteArray();
......@@ -90,24 +86,26 @@ public final class DefineItemTransfer extends ByteArrayTransfer {
for (int i = 0; i < n; i++) {
items[i] = new DefineSectionHandler.Definition();
final ParseTree root = new ParserRuleContext();
items[i].setRoot( root );
hiddenBefore = in.readUTF();
ConfigTreeNodeUtilities.addChild( root, ConfigTreeNodeUtilities.createHiddenTokenNode( hiddenBefore ) );
name = in.readUTF();
items[i].setDefinitionName(new LocationAST(name));
items[i].getDefinitionName().setHiddenBefore(new CommonHiddenStreamToken(hiddenBefore));
final ParseTree nameNode = new AddedParseTree( name );
items[i].setDefinitionName( nameNode );
ConfigTreeNodeUtilities.addChild( root, nameNode );
hiddenBefore = in.readUTF();
LocationAST node = new LocationAST(":=");
node.setHiddenBefore(new CommonHiddenStreamToken(hiddenBefore));
items[i].getDefinitionName().setNextSibling(node);
ConfigTreeNodeUtilities.addChild( root, ConfigTreeNodeUtilities.createHiddenTokenNode( hiddenBefore ) );
ConfigTreeNodeUtilities.addChild( root, new AddedParseTree(":=") );
hiddenBefore = in.readUTF();
ConfigTreeNodeUtilities.addChild( root, ConfigTreeNodeUtilities.createHiddenTokenNode( hiddenBefore ) );
value = in.readUTF();
items[i].setDefinitionValue(new LocationAST(value));
items[i].getDefinitionValue().setHiddenBefore(new CommonHiddenStreamToken(hiddenBefore));
node.setNextSibling(items[i].getDefinitionValue());
items[i].setRoot(new LocationAST(""));
items[i].getRoot().setFirstChild(items[i].getDefinitionName());
final ParseTree valueNode = new AddedParseTree( value );
items[i].setDefinitionValue( valueNode );
ConfigTreeNodeUtilities.addChild( root, valueNode );
}
return items;
} catch (IOException e) {
......
......@@ -13,17 +13,18 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.antlr.v4.runtime.tree.ParseTree;
import org.eclipse.swt.dnd.TransferData;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.common.parsers.CommonHiddenStreamToken;
import org.eclipse.titan.common.parsers.LocationAST;
import org.eclipse.titan.common.parsers.AddedParseTree;
import org.eclipse.titan.common.parsers.cfg.ConfigTreeNodeUtilities;
import org.eclipse.titan.designer.editors.configeditor.ConfigItemTransferBase;
/**
* @author Kristof Szabados
* */
public final class IncludeItemTransfer extends ByteArrayTransfer {
* @author Arpad Lovassy
*/
public final class IncludeItemTransfer extends ConfigItemTransferBase {
private static IncludeItemTransfer instance = new IncludeItemTransfer();
private static final String TYPE_NAME = "TITAN-IncludeItem-transfer-format";
private static final int TYPEID = registerType(TYPE_NAME);
......@@ -44,7 +45,7 @@ public final class IncludeItemTransfer extends ByteArrayTransfer {
@Override
protected void javaToNative(final Object object, final TransferData transferData) {
LocationAST[] items = (LocationAST[]) object;
ParseTree[] items = (ParseTree[]) object;
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
......@@ -54,8 +55,7 @@ public final class IncludeItemTransfer extends ByteArrayTransfer {
out.writeInt(items.length);
for (int i = 0; i < items.length; i++) {
out.writeUTF(ConfigTreeNodeUtilities.getHiddenBefore(items[i]));
out.writeUTF(items[i].getText());
out.writeUTF( convertToString( items[ 2 * i + 1 ] ) );
}
out.close();
bytes = byteOut.toByteArray();
......@@ -69,26 +69,26 @@ public final class IncludeItemTransfer extends ByteArrayTransfer {
}
@Override
protected LocationAST[] nativeToJava(final TransferData transferData) {
protected ParseTree[] nativeToJava(final TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
try {
int n = in.readInt();
LocationAST[] items = new LocationAST[n];
ParseTree[] items = new ParseTree[ 2 * n ];
String fileName;
String hiddenBefore;
for (int i = 0; i < n; i++) {
hiddenBefore = in.readUTF();
fileName = in.readUTF();
items[i] = new LocationAST(fileName);
items[i].setHiddenBefore(new CommonHiddenStreamToken(hiddenBefore));
items[ 2 * i ] = ConfigTreeNodeUtilities.createHiddenTokenNode( hiddenBefore );
items[ 2 * i + 1 ] = new AddedParseTree(fileName);
}
return items;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
return new LocationAST[] {};
return new ParseTree[] {};
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment