package org.schertel.friederike.ecliphistory.view;

import java.util.Observable;
import java.util.Observer;

import org.eclipse.e4.ui.di.Focus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;
import org.schertel.friederike.ecliphistory.model.ClipboardHistory;
import org.schertel.friederike.ecliphistory.model.ClipboardHistoryEntry;
import org.schertel.friederike.ecliphistory.util.LogUtility;

public class EClipHistoryViewPart extends ViewPart implements Observer {

	private Label lblHistory;
	private Label lblLatestEntry;
	private Label lblNumberOfEntries;
	private Label lblEntries;
	private Button btnUpdate;

	public EClipHistoryViewPart() {
		// do nothing
	}

	@Focus
	public void setFocus() {
		LogUtility.debug("setFocus");
		lblHistory.setFocus();
	}

	private void updateContent() {
		lblNumberOfEntries.setText(String.format("%d", ClipboardHistory
				.getInstance().size()));
		lblNumberOfEntries.pack();

		ClipboardHistoryEntry latestEntry = ClipboardHistory.getInstance()
				.getItem(0);
		lblLatestEntry.setText("");
		if (latestEntry != null) {
			lblLatestEntry.setText(latestEntry.content);
		}
	}

	@Override
	public void createPartControl(Composite parent) {
		parent.setLayout(new GridLayout(2, false));

		lblHistory = new Label(parent, SWT.NONE);
		GridData gd_lblHistory = new GridData(SWT.FILL, SWT.CENTER, true,
				false, 2, 1);
		gd_lblHistory.widthHint = 442;
		lblHistory.setLayoutData(gd_lblHistory);
		lblHistory.setText("History");

		lblEntries = new Label(parent, SWT.NONE);
		lblEntries.setText("Entries: ");

		lblNumberOfEntries = new Label(parent, SWT.NONE);
		lblNumberOfEntries.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,
				true, false, 1, 1));
		lblNumberOfEntries.setText("0");

		lblLatestEntry = new Label(parent, SWT.NONE);
		lblLatestEntry.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 2, 1));
		lblLatestEntry.setText("[latest entry]");
		new Label(parent, SWT.NONE);
		new Label(parent, SWT.NONE);

		btnUpdate = new Button(parent, SWT.NONE);
		btnUpdate.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				updateContent();
			}
		});
		btnUpdate.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 2, 1));
		btnUpdate.setText("Update");
		
		ClipboardHistory.getInstance().addObserver(this);

		updateContent();
	}

	@Override
	public void update(Observable o, Object arg) {
		updateContent();
	}

}

@@ -169,102 +169,8 @@
 WT;%0A
-import org.eclipse.swt.events.SelectionAdapter;%0Aimport org.eclipse.swt.events.SelectionEvent;%0A
 impo
@@ -251,47 +251,8 @@
 ut;%0A
-import org.eclipse.swt.widgets.Button;%0A
 impo
@@ -321,20 +321,19 @@
 idgets.L
-abel
+ist
 ;%0Aimport
@@ -639,17 +639,16 @@
 erver %7B%0A
-%0A
 %09private
@@ -653,143 +653,16 @@
 te L
-abel lblHistory;%0A%09private Label lblLatestEntry;%0A%09private Label lblNumberOfEntries;%0A%09private Label lblEntries;%0A%09private Button btnUpdate
+ist list
 ;%0A%0A%09
@@ -778,33 +778,27 @@
 Focus%22);%0A%09%09l
-blHistory
+ist
 .setFocus();
@@ -840,54 +840,31 @@
 %7B%0A%09%09
-lblNumberOfEntries.setText(String.format(%22%25d%22,
+ClipboardHistory clip =
  Cli
@@ -876,21 +876,16 @@
 dHistory
-%0A%09%09%09%09
 .getInst
@@ -894,245 +894,184 @@
 ce()
-.size()));%0A%09%09lblNumberOfEntries.pack();%0A%0A%09%09ClipboardHistoryEntry latestEntry = ClipboardHistory.getInstance()%0A%09%09%09%09.getItem(0);%0A%09%09lblLatestEntry.setText(%22%22);%0A%09%09if (latestEntry != null) %7B%0A%09%09%09lblLatestEntry.setText(latestEntry.content);%0A%09%09%7D
+;%0A%09%09String%5B%5D strings = new String%5Bclip.size()%5D;%0A%09%09for (ClipboardHistoryEntry entry : clip.getList()) %7B%0A%09%09%09strings%5Bentry.position%5D = entry.content;%0A%09%09%7D%0A%09%09list.setItems(strings);
 %0A%09%7D%0A
@@ -1167,17 +1167,17 @@
 dLayout(
-2
+1
 , false)
@@ -1187,25 +1187,19 @@
 %0A%09%09l
-blHistory
+ist
  = new L
 abel
@@ -1186,36 +1186,35 @@
 %0A%0A%09%09list = new L
-abel
+ist
 (parent, SWT.NON
@@ -1214,1038 +1214,121 @@
 SWT.
-NONE);%0A%09%09GridData gd_lblHistory = new GridData(SWT.FILL, SWT.CENTER, true,%0A%09%09%09%09false, 2, 1);%0A%09%09gd_lblHistory.widthHint = 442;%0A%09%09lblHistory.setLayoutData(gd_lblHistory);%0A%09%09lblHistory.setText(%22History%22);%0A%0A%09%09lblEntries = new Label(parent, SWT.NONE);%0A%09%09lblEntries.setText(%22Entries: %22);%0A%0A%09%09lblNumberOfEntries = new Label(parent, SWT.NONE);%0A%09%09lblNumberOfEntries.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,%0A%09%09%09%09true, false, 1, 1));%0A%09%09lblNumberOfEntries.setText(%220%22);%0A%0A%09%09lblLatestEntry = new Label(parent, SWT.NONE);%0A%09%09lblLatestEntry.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,%0A%09%09%09%09false, 2, 1));%0A%09%09lblLatestEntry.setText(%22%5Blatest entry%5D%22);%0A%09%09new Label(parent, SWT.NONE);%0A%09%09new Label(parent, SWT.NONE);%0A%0A%09%09btnUpdate = new Button(parent, SWT.NONE);%0A%09%09btnUpdate.addSelectionListener(new SelectionAdapter() %7B%0A%09%09%09@Override%0A%09%09%09public void widgetSelected(SelectionEvent e) %7B%0A%09%09%09%09updateContent();%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09btnUpdate.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,%0A%09%09%09%09false, 2, 1));%0A%09%09btnUpdate.setText(%22Update%22);%0A%09%09
+BORDER %7C SWT.H_SCROLL %7C SWT.V_SCROLL);%0A%09%09list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));%0A
 %0A%09%09C

Liste im View