Source code file content
granite / src / org / pushingpixels / granite / DemoApp.java
Size: 6280 bytes, 1 line
/*
* Copyright (c) 2009 Granite Kirill Grouchnikov. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* o Neither the name of Granite Kirill Grouchnikov nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.pushingpixels.granite;
import java.util.List;
import javax.xml.ws.Holder;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.pushingpixels.granite.details.DetailsWindowManager;
import org.pushingpixels.trident.Timeline;
import com.ECS.client.jax.*;
public class DemoApp {
MainContentPanel mainContentPanel;
String awsKey;
public DemoApp(Shell shell, String awsKey) {
this.awsKey = awsKey;
this.mainContentPanel = new MainContentPanel(shell);
}
public void doLoad(final String searchString) throws Exception {
mainContentPanel.setLoading(true);
Job job = new Job("Fetch Amazon") {
@Override
protected org.eclipse.core.runtime.IStatus run(
org.eclipse.core.runtime.IProgressMonitor monitor) {
System.out.println("Searching");
try {
final List<Items> result = doSearch("Sarah McLachlan");
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
for (Items i : result) {
for (final Item ii : i.getItem()) {
// push the album item to the screen
AlbumOverviewComponent albumOverviewComp = mainContentPanel
.addAlbumItem(ii);
albumOverviewComp
.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(
org.eclipse.swt.events.MouseEvent e) {
DetailsWindowManager
.show(
mainContentPanel
.getShell(),
ii);
};
});
}
}
System.out.println("Done searching");
mainContentPanel.setLoading(false);
}
});
} catch (Throwable exc) {
exc.printStackTrace();
System.out.println("Failed searching");
mainContentPanel.setLoading(false);
return null;
}
return Status.OK_STATUS;
}
};
job.schedule();
}
private java.util.List<Items> doSearch(String searchString)
throws Exception {
AWSECommerceService service = new AWSECommerceService();
AWSECommerceServicePortType port = service.getAWSECommerceServicePort();
ItemSearchRequest shared = new ItemSearchRequest();
shared.setSearchIndex("Music");
shared.setKeywords(searchString);
shared.getResponseGroup().add("Medium");
shared.getResponseGroup().add("Tracks");
ItemSearch itemSearch = new ItemSearch();
itemSearch.setShared(shared);
String marketplaceDomain = "";
String awsAccessKeyId = this.awsKey;
String subscriptionId = "";
String associateTag = "";
String xmlEscaping = "Single";
String validate = "";
java.util.List<ItemSearchRequest> itemsSearchRequests = null;
Holder<OperationRequest> operationRequest = null;
Holder<java.util.List<Items>> items = new Holder<java.util.List<Items>>();
port.itemSearch(marketplaceDomain, awsAccessKeyId, subscriptionId,
associateTag, xmlEscaping, validate, shared,
itemsSearchRequests, operationRequest, items);
return items.value;
}
public static void main(final String[] args) throws Exception {
try {
System.setProperty("java.net.useSystemProxies", "true");
} catch (SecurityException e) {
}
if (args.length != 1) {
System.out.println("Needs the Amazon e-Commerce access key ID");
System.exit(0);
}
Display display = new Display();
Shell shell = new Shell(display, SWT.NO_TRIM);
final DemoApp app = new DemoApp(shell, args[0]);
shell.setLayout(new FillLayout());
// center the shell in the display bounds
Rectangle pDisplayBounds = shell.getDisplay().getBounds();
int width = 480;
int height = 200;
shell.setBounds((pDisplayBounds.width - width) / 2,
(pDisplayBounds.height - height) / 2, width, height);
shell.setAlpha(0);
shell.open();
Timeline fadeInShellTimeline = new Timeline(shell);
fadeInShellTimeline.addPropertyToInterpolate("alpha", 0, 255);
fadeInShellTimeline.setDuration(500);
fadeInShellTimeline.play();
display.asyncExec(new Runnable() {
@Override
public void run() {
try {
app.doLoad("Sarah McLachlan");
} catch (Exception e) {
}
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}






