Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Compare » Problem with compare editor(I can't save modified content in the workspace with my compare editor)
Problem with compare editor [message #1827114] Thu, 07 May 2020 12:27
Jorge Plaza is currently offline Jorge PlazaFriend
Messages: 1
Registered: May 2020
Junior Member
Hi. I have a problem.

I have a RCP project for eclipse. I have created a source code comparer.

I have a class to editor comparer, and class to extract the files in the workspace.

I need to save the modifications I make on the left side of the editor.
I need it to appear * symbol when the changes have not been saved.

My editor compare class:
// Configuration options
private CompareConfiguration fCompareConfiguration;
private List<Object> fArrayList= new ArrayList<Object>();
/** use a side-by-side compare viewer */
private boolean fCompare= true;
/** show target on right hand side */
private boolean fTargetIsRight= false;
/** hide entries which have identical content */
private boolean fHideIdentical= true;
/** add mode if true, otherwise replace mode */
private boolean fAddMode= false;
/** compare mode if true, otherwise replace/add mode */
// private boolean fCompareMode= false;
/** perform structure compare on editions */
private boolean fStructureCompare= true;
/** allow for multiple selection */
private boolean fMultiSelect= false;

private boolean noDiferences= false;

// SWT controls
private CompareViewerSwitchingPane fContentPane;
private Button fCommitButton;
private Table fMemberTable;
private CompareViewerPane fMemberPane;
private Tree fEditionTree;
private CompareViewerPane fEditionPane;
private Image fDateImage;
private Image fTimeImage;
private CompareViewerSwitchingPane fStructuredComparePane;
private Label statusLabel;

/**
* Maps from members to their corresponding editions.
* Has only a single entry if dialog is used in "Replace" (and not "Add") mode.
*/
private Map<Object, Object> fMemberEditions;
/**
* Maps from members to their corresponding selected edition.
*/
private Map<Object, Object> fMemberSelection;
/** The editions of the current selected member */
private List<Object> fCurrentEditions;
private Thread fThread;
private Pair fTargetPair;
/** The selected edition in the edition viewer */
private ITypedElement fSelectedItem;
private String fTitleArg;
private Image fTitleImage;

private boolean compareLocalFiles;

@Inject EPartService partService;
@Inject MPart part;

@PostConstruct
public void create(Composite parent)
{
parent.setLayout(new GridLayout(1, true));

createCompartorArea(parent);

MergeCompareEditor he = new MergeCompareEditor(fCompareConfiguration);
he.setDirty(true);
}

public void createCompartorArea(Composite parent) {
Splitter vsplitter= new Splitter(parent, SWT.VERTICAL);
vsplitter.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL
| GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL));


vsplitter.addDisposeListener(
new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
if (fCompareConfiguration != null) {
fCompareConfiguration.dispose();
fCompareConfiguration= null;
}
if (fDateImage != null) {
fDateImage.dispose();
fDateImage= null;
}
if (fTimeImage != null) {
fTimeImage.dispose();
fTimeImage= null;
}
}
}
);

if (fAddMode) {
// we need two panes: the left for the elements, the right one for the editions
Splitter hsplitter= new Splitter(vsplitter, SWT.HORIZONTAL);

fMemberPane= new CompareViewerPane(hsplitter, SWT.BORDER | SWT.FLAT);
fMemberPane.setText(Utilities.getString(fBundle, "memberPaneTitle")); //$NON-NLS-1$

int flags= SWT.H_SCROLL | SWT.V_SCROLL;
if (fMultiSelect)
flags|= SWT.CHECK;
fMemberTable= new Table(fMemberPane, flags);
fMemberTable.addSelectionListener(
new SelectionAdapter() {


public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
if (e.item instanceof TableItem) {
TableItem ti= (TableItem) e.item;
Object data= ti.getData();
if (ti.getChecked())
fArrayList.add(data);
else
fArrayList.remove(data);

if (fCommitButton != null)
fCommitButton.setEnabled(fArrayList.size() > 0);

fMemberTable.setSelection(new TableItem[] { ti });
}
}
handleMemberSelect(e.item);
}
}
);
fMemberPane.setContent(fMemberTable);
fMemberTable.setFocus();

fEditionPane= new CompareViewerPane(hsplitter, SWT.BORDER | SWT.FLAT);
} else {
if (fStructureCompare) {
// we need two panes: the left for the elements, the right one for the structured diff
Splitter hsplitter= new Splitter(vsplitter, SWT.HORIZONTAL);

fEditionPane= new CompareViewerPane(hsplitter, SWT.BORDER | SWT.FLAT);
fStructuredComparePane= new CompareViewerSwitchingPane(hsplitter, SWT.BORDER | SWT.FLAT, true) {
protected Viewer getViewer(Viewer oldViewer, Object input) {
if (input instanceof ICompareInput)
return CompareUI.findStructureViewer(oldViewer, (ICompareInput)input, this, getCompareConfiguration());
return null;
}
};
fStructuredComparePane.addSelectionChangedListener(
new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent e) {
feedInput2(e.getSelection());
}
}
);
} else {
// only a single pane showing the editions
fEditionPane= new CompareViewerPane(vsplitter, SWT.BORDER | SWT.FLAT);
}

String titleFormat= Utilities.getString(fBundle, "treeTitleFormat"); //$NON-NLS-1$
String title= MessageFormat.format(titleFormat, new String[] { fTitleArg });
fEditionPane.setText(title);

if (fTitleImage != null)
fEditionPane.setImage(fTitleImage);
}

fEditionTree= new Tree(fEditionPane, SWT.H_SCROLL | SWT.V_SCROLL);
fEditionTree.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
feedInput(e.item);
}
}
);
fEditionPane.setContent(fEditionTree);

// now start the thread (and forget about it)
if (fThread != null) {
fThread.start();
fThread= null;
}

fContentPane= new CompareViewerSwitchingPane(vsplitter, SWT.BORDER | SWT.FLAT) {
protected Viewer getViewer(Viewer oldViewer, Object input) {
return CompareUI.findContentViewer(oldViewer, input, this, getCompareConfiguration());
}
};
vsplitter.setWeights(new int[] { 30, 80 });

statusLabel = new Label(parent, SWT.NONE);
statusLabel.setLayoutData(new GridData(GridData.FILL, GridData.END, false, false));
}

/*
* Feeds selection from structure viewer to content viewer.
*/
private void feedInput2(ISelection sel) {
if (sel instanceof IStructuredSelection) {
IStructuredSelection ss= (IStructuredSelection) sel;
if (ss.size() == 1)
fContentPane.setInput(ss.getFirstElement());
}
}

private CompareConfiguration getCompareConfiguration() {
if (fCompareConfiguration == null) {
fCompareConfiguration= new CompareConfiguration();
fCompareConfiguration.setLeftEditable(true);
fCompareConfiguration.setRightEditable(false);
fCompareConfiguration.setContainer(new CompareContainer() {
public void setStatusMessage(String message) {
if (statusLabel != null && !statusLabel.isDisposed()) {
if (message == null) {
statusLabel.setText(""); //$NON-NLS-1$
} else {
statusLabel.setText(message);
}
}
}
});
}
return fCompareConfiguration;
}

/**
* Returns a label for identifying the edition side of a compare viewer.
* This implementation extracts the value for the key "editionLabel" from the resource bundle
* and passes it as the format argument to <code>MessageFormat.format</code>.
* The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string)
* is the formatted modification date of the given input element.
* <p>
* Subclasses may override to create their own label.
* </p>
*
* @param selectedEdition the selected edition for which a label must be returned
* @param item if a path has been specified in <code>selectEdition</code> a sub element of the given selectedEdition; otherwise the same as selectedEdition
* @return a label for the edition side of a compare viewer
*/
protected String getEditionLabel(ITypedElement selectedEdition, ITypedElement item) {
String format= null;
if (selectedEdition instanceof ResourceNode)
format= Utilities.getString(fBundle, "workspaceEditionLabel", null); //$NON-NLS-1$
else if (selectedEdition instanceof HistoryItem)
format= Utilities.getString(fBundle, "historyEditionLabel", null); //$NON-NLS-1$
else if( selectedEdition instanceof CompareItem)
{
String[] splitPoint = selectedEdition.getName().split("\\.");
format = selectedEdition.getName();
if(splitPoint.length>2)
format = Utilidades.restoPrimerPunto(selectedEdition.getName());
}
if (format == null)
format= Utilities.getString(fBundle, "editionLabel"); //$NON-NLS-1$
if (format == null)
format= "x{0}"; //$NON-NLS-1$


String date= ""; //$NON-NLS-1$
if (selectedEdition instanceof IModificationDate) {
long modDate= ((IModificationDate)selectedEdition).getModificationDate();
date= DateFormat.getDateTimeInstance().format(new Date(modDate));
}

return formatString(format, date);
}

private String formatString(String string, String variable) {
// Only process the string if it contains a variable or an escaped quote (see bug 190023)
if (hasVariable(string) || hasDoubleQuotes(string))
return MessageFormat.format(string, new Object[] { variable });
return string;
}

private boolean hasDoubleQuotes(String string) {
return string.indexOf("''") != -1; //$NON-NLS-1$
}

private boolean hasVariable(String string) {
return string.indexOf("{0}") != -1; //$NON-NLS-1$
}

/**
* Returns an image for identifying the edition side of a compare viewer.
* This implementation extracts the value for the key "editionLabel" from the resource bundle
* and passes it as the format argument to <code>MessageFormat.format</code>.
* The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string)
* is the formatted modification date of the given input element.
* <p>
* Subclasses may override to create their own label.
* </p>
*
* @param selectedEdition the selected edition for which a label must be returned
* @param item if a path has been specified in <code>selectEdition</code> a sub element of the given selectedEdition; otherwise the same as selectedEdition
* @return a label the edition side of a compare viewer
* @since 2.0
*/
protected Image getEditionImage(ITypedElement selectedEdition, ITypedElement item) {
if (selectedEdition instanceof ResourceNode)
return selectedEdition.getImage();
if (selectedEdition instanceof HistoryItem) {
if (fTimeImage == null) {
String iconName= Utilities.getString(fBundle, "timeIcon", "obj16/resource_obj.gif"); //$NON-NLS-1$ //$NON-NLS-2$
ImageDescriptor id= CompareUIPlugin.getImageDescriptor(iconName);
if (id != null)
fTimeImage= id.createImage();
}
return fTimeImage;
}
return null;
}

/*
* Feeds selection from edition viewer to content (and structure) viewer.
*/
private void feedInput(Widget w) {
Object input= w.getData();
boolean isOK= false;
if (input instanceof Pair) {
Pair pair= (Pair) input;
fSelectedItem= pair.getItem();
isOK= !pair.fHasError;

ITypedElement edition= pair.getEdition();
String editionLabel= getEditionLabel(edition, fSelectedItem);
Image editionImage= getEditionImage(edition, fSelectedItem);

if (fAddMode) {
if (fMemberSelection != null)
fMemberSelection.put(fCurrentEditions, fSelectedItem);
setInput(fSelectedItem);
fContentPane.setText(editionLabel);
fContentPane.setImage(editionImage);
} else {
getCompareConfiguration();
if (fTargetIsRight) {
fCompareConfiguration.setLeftLabel(editionLabel);
fCompareConfiguration.setLeftImage(editionImage);
setInput(new DiffNode(fSelectedItem, fTargetPair.getItem()));
} else {
fCompareConfiguration.setRightLabel(editionLabel);
fCompareConfiguration.setRightImage(editionImage);
setInput(new DiffNode(fTargetPair.getItem(), fSelectedItem));
}
}
} else {
fSelectedItem= null;
setInput(null);
}
if (fCommitButton != null) {
if (fMultiSelect)
fCommitButton.setEnabled(isOK && fSelectedItem != null && fArrayList.size() > 0);
else
fCommitButton.setEnabled(isOK && fSelectedItem != null && fTargetPair.getItem() != fSelectedItem);
}
}

public void setInput(Object input) {
if (!fCompare && input instanceof ICompareInput) {
ICompareInput ci= (ICompareInput) input;
if (fTargetIsRight)
input= ci.getLeft();
else
input= ci.getRight();
}
fContentPane.setInput(input);
if (fStructuredComparePane != null)
fStructuredComparePane.setInput(input);
}

/**
* Presents this modal dialog with the functionality described in the class comment above.
*
* @param target the input object against which the editions are compared; must not be <code>null</code>
* @param inputEditions the list of editions (element type: <code>ITypedElement</code>s)
* @param ppath If <code>null</code> dialog shows full input; if non <code>null</code> it extracts a subsection
* @return returns the selected edition or <code>null</code> if dialog was cancelled.
* The returned <code>ITypedElement</code> is one of the original editions
* if <code>path</code> was <code>null</code>; otherwise
* it is an <code>ITypedElement</code> returned from <code>IStructureCreator.locate(path, item)</code>
*/
public ITypedElement selectEdition(final ITypedElement target, ITypedElement[] inputEditions, Object ppath) {

Assert.isNotNull(target);
fTargetPair= new Pair(null, target);

if (fTitleArg == null)
fTitleArg= fTargetPair.getItem().getName();

String titleFormat= Utilities.getString(fBundle, "treeTitleFormat"); //$NON-NLS-1$
String title= MessageFormat.format(titleFormat, new String[] { fTitleArg });
fEditionPane.setText(title);

// compare local files, remove history info parts
if(inputEditions.length==1 && inputEditions[0] instanceof CompareItem)
compareLocalFiles = true;

// sort input editions
final int count= inputEditions.length;
final IModificationDate[] editions= new IModificationDate[count];
for (int i= 0; i < count; i++)
editions[i]= (IModificationDate) inputEditions[i];
if (count > 1)
internalSort(editions);

// find StructureCreator if ppath is not null
IStructureCreator structureCreator= null;
if (ppath != null) {
String type= target.getType();
StructureCreatorDescriptor scd= CompareUIPlugin.getDefault().getStructureCreator(type);
if (scd != null)
structureCreator= scd.createStructureCreator();
}

if (!fAddMode) {
// replace mode

if (structureCreator != null) {
Pair pair= createPair(structureCreator, ppath, target);
if (pair != null)
fTargetPair= pair;
else
ppath= null; // couldn't extract item because of error
}

// set the left and right labels for the compare viewer
String targetLabel= getTargetLabel(target, fTargetPair.getItem());
if (fTargetIsRight)
getCompareConfiguration().setRightLabel(targetLabel);
else
getCompareConfiguration().setLeftLabel(targetLabel);

if (structureCreator != null && ppath != null) { // extract sub element

final IStructureCreator sc= structureCreator;
final Object path= ppath;

// construct the comparer thread
// and perform the background extract
fThread= new Thread() {
public void run() {

// from front (newest) to back (oldest)
for (int i= 0; i < count; i++) {

if (fEditionTree == null || fEditionTree.isDisposed())
break;
ITypedElement edition= (ITypedElement) editions[i];

// extract sub element from edition
Pair pair= createPair(sc, path, edition);
if (pair != null)
sendPair(pair);
}
sendPair(null);
}
};
} else {
// create tree widget
// create();

// from front (newest) to back (oldest)
for (int i= 0; i < count; i++)
addMemberEdition(new Pair(null, (ITypedElement) editions[i]));
}

} else {
// add mode
final Object container= ppath;
Assert.isNotNull(container);

if (structureCreator == null)
return null; // error

// extract all elements of container
final Set current= new HashSet();
IStructureComparator sco= structureCreator.locate(container, target);
if (sco != null) {
Object[] children= sco.getChildren();
if (children != null)
for (int i= 0; i < children.length; i++)
current.add(children[i]);
}

final IStructureCreator sc= structureCreator;

// construct the comparer thread
// and perform the background extract
fThread= new Thread() {
public void run() {

// from front (newest) to back (oldest)
for (int i= 0; i < count; i++) {

if (fEditionTree == null || fEditionTree.isDisposed())
break;
ITypedElement edition= (ITypedElement) editions[i];

IStructureComparator sco2= sc.locate(container, edition);
if (sco2 != null) {
Object[] children= sco2.getChildren();
if (children != null) {
for (int i2= 0; i2 < children.length; i2++) {
ITypedElement child= (ITypedElement) children[i2];
if (!current.contains(child))
sendPair(new Pair(sc, edition, child));
}
}
}
}
sendPair(null);
}
};
}
if(fSelectedItem == null)
{
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Comparador de ficheros", "No existen diferencias entre los ficheros");
partService.hidePart(part);
}

return fSelectedItem;
}

/*
* Adds the given Pair to the member editions.
* If HIDE_IDENTICAL is true the new Pair is only added if its contents
* is different from the preceeding Pair.
* If the argument is <code>null</code> the message "No Editions found" is shown
* in the member or edition viewer.
*/
@SuppressWarnings("unchecked")
private void addMemberEdition(Pair pair) {

if(compareLocalFiles)
{
String titleFormat= "Comparador de archivos"; //$NON-NLS-1$
fEditionPane.setText(titleFormat);

fEditionTree.setVisible(false);
}

if (pair == null) { // end of list of pairs
if (fMemberTable != null) {
if (!fMemberTable.isDisposed() && fMemberTable.getItemCount() == 0) {
if (fMultiSelect) {
fMemberTable.dispose();
fMemberTable= new Table(fMemberPane, SWT.NONE);
fMemberPane.setContent(fMemberTable);
}
TableItem ti= new TableItem(fMemberTable, SWT.NONE);
ti.setText(Utilities.getString(fBundle, "noAdditionalMembersMessage")); //$NON-NLS-1$
}
return;
}
if (fEditionTree != null && !fEditionTree.isDisposed() && fEditionTree.getItemCount() == 0) {
TreeItem ti= new TreeItem(fEditionTree, SWT.NONE);
ti.setText(Utilities.getString(fBundle, "notFoundInLocalHistoryMessage")); //$NON-NLS-1$
}
return;
}

if (fMemberEditions == null)
fMemberEditions= new HashMap<Object, Object>();
if (fMultiSelect && fMemberSelection == null)
fMemberSelection= new HashMap<Object, Object>();

ITypedElement item= pair.getItem();
List<Object> editions= (List<Object>) fMemberEditions.get(item);
if (editions == null) {
editions= new ArrayList<Object>();
fMemberEditions.put(item, editions);
if (fMemberTable != null && !fMemberTable.isDisposed()) {
ITypedElement te= item;
String name= te.getName();

// find position
TableItem[] items= fMemberTable.getItems();
int where= items.length;
for (int i= 0; i < where; i++) {
String n= items[i].getText();
if (n.compareTo(name) > 0) {
where= i;
break;
}
}

TableItem ti= new TableItem(fMemberTable, where, SWT.NULL);
ti.setImage(te.getImage());
ti.setText(name);
ti.setData(editions);
}
}
if (fHideIdentical) {
Pair last= fTargetPair;
int size= editions.size();
if (size > 0)
last= (Pair) editions.get(size-1);
if (last != null && last.equals(pair))
{
noDiferences = true;
return; // don't add since the new one is equal to old
}
}
editions.add(pair);

if ((!fAddMode || editions == fCurrentEditions))
addEdition(pair);
}

private void sendPair(final Pair pair) {
if (fEditionTree != null && !fEditionTree.isDisposed()) {
Display display= fEditionTree.getDisplay();
display.asyncExec(
new Runnable() {
public void run() {
addMemberEdition(pair);
}
}
);
}
}

/**
* Returns a label for identifying the target side of a compare viewer.
* This implementation extracts the value for the key "targetLabel" from the resource bundle
* and passes it as the format argument to <code>MessageFormat.format</code>.
* The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string)
* is the name of the given input element.
* <p>
* Subclasses may override to create their own label.
* </p>
*
* @param target the target element for which a label must be returned
* @param item if a path has been specified in <code>selectEdition</code> a sub element of the given target; otherwise the same as target
* @return a label the target side of a compare viewer
*/
protected String getTargetLabel(ITypedElement target, ITypedElement item) {
String format= null;
if (target instanceof ResourceNode)
format= Utilities.getString(fBundle, "workspaceTargetLabel", null); //$NON-NLS-1$
if (target instanceof CompareItem)
{
String[] splitPoint = target.getName().split("\\.");
format = target.getName();
if(splitPoint.length>2)
format = Utilidades.restoPrimerPunto(target.getName());
}
if (format == null)
format= Utilities.getString(fBundle, "targetLabel"); //$NON-NLS-1$
if (format == null)
format= "x{0}"; //$NON-NLS-1$

return formatString(format, target.getName());
}

private Pair createPair(IStructureCreator sc, Object path, ITypedElement input) {
IStructureComparator scmp= sc.locate(path, input);
if (scmp == null && sc.getStructure(input) == null) { // parse error
Pair p= new Pair(sc, input);
p.fHasError= true;
return p;
}
if (scmp instanceof ITypedElement)
return new Pair(sc, input, (ITypedElement) scmp);
return null;
}

@SuppressWarnings("unchecked")
private static void internalSort(IModificationDate[] keys) {
Arrays.sort(keys, new Comparator() {
public int compare(Object o1, Object o2) {
IModificationDate d1= (IModificationDate) o1;
IModificationDate d2= (IModificationDate) o2;
long d= d2.getModificationDate() - d1.getModificationDate();
if (d < 0)
return -1;
if (d > 0)
return 1;
return 0;
}
});
}

/*
* Feeds selection from member viewer to edition viewer.
*/
@SuppressWarnings("unchecked")
private void handleMemberSelect(Widget w) {
Object data= w.getData();
if (data instanceof List) {
List<Object> editions= (List<Object>) data;
if (editions != fCurrentEditions) {
fCurrentEditions= editions;
fEditionTree.removeAll();

String pattern= Utilities.getString(fBundle, "treeTitleFormat"); //$NON-NLS-1$
String title= MessageFormat.format(pattern, new Object[] { ((Item)w).getText() });
fEditionPane.setText(title);

Iterator<Object> iter= editions.iterator();
while (iter.hasNext()) {
Object item= iter.next();
if (item instanceof Pair)
addEdition((Pair) item);
}
}
}
}

/*
* Adds the given Pair to the edition tree.
* It takes care of creating tree nodes for different dates.
*/
private void addEdition(Pair pair) {
if (fEditionTree == null || fEditionTree.isDisposed())
return;

// find last day
TreeItem[] days= fEditionTree.getItems();
TreeItem lastDay= null;
if (days.length > 0)
lastDay= days[days.length-1];

boolean first= lastDay == null;

ITypedElement edition= pair.getEdition();
ITypedElement item= pair.getItem();

long ldate= ((IModificationDate)edition).getModificationDate();
long day= dayNumber(ldate);
Date date= new Date(ldate);
if (lastDay == null || day != dayNumber(((Date)lastDay.getData()).getTime())) {
lastDay= new TreeItem(fEditionTree, SWT.NONE);
if (fDateImage == null) {
String iconName= Utilities.getString(fBundle, "dateIcon", "obj16/day_obj.gif"); //$NON-NLS-2$ //$NON-NLS-1$
ImageDescriptor id= CompareUIPlugin.getImageDescriptor(iconName);
if (id != null)
fDateImage= id.createImage();
}
lastDay.setImage(fDateImage);
String df= DateFormat.getDateInstance().format(date);
long today= dayNumber(System.currentTimeMillis());

String formatKey;
if (day == today)
formatKey= "todayFormat"; //$NON-NLS-1$
else if (day == today-1)
formatKey= "yesterdayFormat"; //$NON-NLS-1$
else
formatKey= "dayFormat"; //$NON-NLS-1$
String pattern= Utilities.getString(fBundle, formatKey);
if (pattern != null)
df= MessageFormat.format(pattern, new String[] { df });
lastDay.setText(df);
lastDay.setData(date);
}
TreeItem ti= new TreeItem(lastDay, SWT.NONE);
ti.setImage(getEditionImage(edition, item));

String s= getShortEditionLabel(edition, item, date);
if (pair.fHasError) {
String pattern= Utilities.getString(fBundle, "parseErrorFormat"); //$NON-NLS-1$
s= MessageFormat.format(pattern, new String[] { s } );
}
ti.setText(s);

ti.setData(pair);

// determine selected TreeItem
TreeItem selection= first ? ti : null;
if (fMemberSelection != null) {
Object selected= fMemberSelection.get(fCurrentEditions);
if (selected != null) {
if (selected == pair.getItem())
selection= ti;
else
selection= null;
}
}
if (selection != null) {
fEditionTree.setSelection(new TreeItem[] { selection });
if (!fAddMode)
fEditionTree.setFocus();
feedInput(selection);
}

if (first) // expand first node
lastDay.setExpanded(true);
}

/**
* Returns a label for identifying a node in the edition tree viewer.
* This implementation extracts the value for the key "workspaceTreeFormat" or
* "treeFormat" (in that order) from the resource bundle
* and passes it as the format argument to <code>MessageFormat.format</code>.
* The single format argument for <code>MessageFormat.format</code> ("{0}" in the format string)
* is the formatted modification date of the given input element.
* <p>
* Subclasses may override to create their own label.
* </p>
*
* @param edition the edition for which a label must be returned
* @param item if a path has been specified in <code>edition</code> a sub element of the given edition; otherwise the same as edition
* @param date this date will be returned as part of the formatted string
* @return a label of a node in the edition tree viewer
* @since 2.0
*/
protected String getShortEditionLabel(ITypedElement edition, ITypedElement item, Date date) {
String format= null;
if (edition instanceof ResourceNode)
format= Utilities.getString(fBundle, "workspaceTreeFormat", null); //$NON-NLS-1$
if (edition instanceof CompareItem)
{
String[] splitPoint = edition.getName().split("\\.");
format = edition.getName();
if(splitPoint.length>2)
format = Utilidades.restoPrimerPunto(edition.getName());
}
if (format == null)
format= Utilities.getString(fBundle, "treeFormat", null); //$NON-NLS-1$
if (format == null)
format= "x{0}"; //$NON-NLS-1$

String ds= DateFormat.getTimeInstance().format(date);
return formatString(format, ds);
}

/*
* Returns the number of s since Jan 1st, 1970.
* The given date is converted to GMT and daylight saving is taken into account too.
*/
private long dayNumber(long date) {
int ONE_DAY_MS= 24*60*60 * 1000; // one day in milli seconds

Calendar calendar= Calendar.getInstance();
long localTimeOffset= calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET);

return (date + localTimeOffset) / ONE_DAY_MS;
}

/**
* An item in an underlying edition.
*/
private static class Pair {

private ITypedElement fEdition;
private ITypedElement fItem;
private String fContent;
private IStructureCreator fStructureCreator;
private boolean fHasError= false;

Pair(IStructureCreator structureCreator, ITypedElement edition, ITypedElement item) {
fStructureCreator= structureCreator;
fEdition= edition;
fItem= item;
}

Pair(IStructureCreator structureCreator, ITypedElement edition) {
this(structureCreator, edition, edition);
}

ITypedElement getEdition() {
return fEdition;
}

ITypedElement getItem() {
return fItem;
}

/*
* The content is lazily loaded
*/
private String getContent() {
if (fContent == null) {
if (fStructureCreator != null)
fContent= fStructureCreator.getContents(fItem, false);
else {
if (fItem instanceof IStreamContentAccessor) {
IStreamContentAccessor sca= (IStreamContentAccessor) fItem;
try {
fContent= Utilities.readString(sca);
} catch (CoreException ex) {
// NeedWork
CompareUIPlugin.log(ex);
}
}
}
if (fContent == null)
fContent= ""; //$NON-NLS-1$
}
return fContent;
}

public boolean equals(Object other) {
if (other != null && other.getClass() == getClass()) {
if (getContent().equals(((Pair)other).getContent()))
return true;
}
return super.equals(other);
}

public int hashCode() {
return getContent().hashCode();
}
}
}

Thanks for help me.
Previous Topic:Error when Define a Custom Identifier
Next Topic:Repository for 3.3
Goto Forum:
  


Current Time: Wed Dec 11 16:14:36 GMT 2024

Powered by FUDForum. Page generated in 0.03994 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top