Search This Blog

Friday, February 8, 2013

Java generic methods; Java generic classes; Java static generic method

Java has a different syntax for generic methods, generic classes and static generic methods.

  • Java generic classes
public class ComboBoxDefinition<T extends Identifiable> extends AbstractFieldDefinition implements xxxx
{
    protected ComboBoxDefinition(BeanContainer<T> beanContainer)
    {
    }
}
  • Java generic methods
public class ComboBoxDefinition
{
    public void draw(List<? extends Control> controls) {
    }
}
  • Java static generic methods
public class SomeClass
{
     public static <T extends Identifiable> void create(BeanContainer<T> beanContainer) {
        
    }
}

Silverlight call simple get (REST/HTTP) and receive an image

This is the simplest method to receive an image from http server - we receive a stream with the message.


var wc = new System.Net.WebClient();
var applicationHostSource = Application.Current.Host.Source;
var request = "http://" + applicationHostSource.Host + ":" + applicationHostSource.Port +"/" + "Image.png";
wc.OpenReadCompleted += (sender, downloadStreamCompletedEventArgs) =>
{
var stream = downloadStreamCompletedEventArgs.Result;
var image = new BitmapImage();
image.SetSource(stream);
StoredImage = image;
};

wc.OpenReadAsync(new Uri(request));

Monday, January 7, 2013

Aero2 Poland APN settings

Aero 2 is an operator that serves free internet access in Poland. To set APN settings in Aero2 on an Android device just enter these:


Nazwa: darmowy
APN: darmowy
Proxy: <nie ustawiono>
Port: <nie ustawiono>
Nazwa Użytkownika: <nie ustawiono>
Hasło: <nie ustawiono>
Serwer: <nie ustawiono>
MMSC: <nie ustawiono>
Proxy dla wiadomości MMS: <nie ustawiono>
Port MMS: <nie ustawiono>
Protokół MMS: <nie ustawiono>
MCC: 260
MNC: 17
Typ uwierzetylnienia: <nie ustawiono>
Typ APN: <nie ustawiono>



Name: darmowy
APN: darmowy
Proxy: <nie ustawiono>
Port: <nie ustawiono>
Username: <nie ustawiono>
Password: <nie ustawiono>
Server: <nie ustawiono>
MMSC: <nie ustawiono>
MMS message proxy: <nie ustawiono>
MMS port: <nie ustawiono>
MMS Protocol: <nie ustawiono>
MCC: 260
MNC: 17
Authorization type: <nie ustawiono>
APN type: <nie ustawiono>

Thursday, January 3, 2013

Devexpress PrivotGridField header template in RowArea

Here's a little image that should help in understanding which templates work for which parts of DevExpress PivotGrid. My goal was to change the header of the row in PivotGrid (to be precise the header of the PivotGridField in RowArea)


<dxpg:PivotGridField x:Name="fieldProduct" FieldName="ProductName" Area="RowArea" AreaIndex="2" AllowedAreas="RowArea" ValueTemplate="{StaticResource productNameHeaderTemplate}" />


Sunday, December 23, 2012

Java Vaadin controls - ControlHelper getParent()

Vaadin controls, just like every other UI, creates a child-parent tree. This class helps to retrieve parent of a specified type. getParent() is extremely useful when invoked deep withing the tree structure to e.g. retrieve the main tab control and close it.


/**
 * The purpose of this class is to help with the management of Vaadin controls child-parent tree.
 */
public class ControlHelper {

    private static final int _MAXIMUM_PARENT_ITERATION_COUNT = 100;

    /**
     * Get parent of the control which has a specified type.
     *
     * @param cls type of the control to return
     * @param control origin control (where to start traversing the tree)
     * @param <T>
     * @return
     */
    public static <T extends AbstractComponent> T getParent(Class<T> cls, AbstractComponent control)
    {
       if (control == null)
           return null;

        AbstractComponent parent = control;

       for (int i = 0; i < _MAXIMUM_PARENT_ITERATION_COUNT; i++)
       {
           if (parent.getParent() == null)
               return null;

           //Return parent of the desired class type
           if (parent.getParent().getClass().isAssignableFrom(cls))
               return (T) parent.getParent();

           parent = (AbstractComponent) parent.getParent();
       }

       return null;
    }
}

Friday, November 23, 2012

Volvo C30 1.6D 2009 Momentum - Remove overhead console

I came up with the idea of replacing stock courtesy lightning bulbs with 501 LED Extreme Power 1.5W in my Volvo C30. The problem was that I thought it would take about 30 minutes and it took much longer than that. Actually it takes about 1.5 hours if you know what you're doing - luckily with this little tutorial you'll know exactly what to do.

Removing the overhead console from the headliner
To remove the overhead console from the headliner just pull the console FIRMLY downward. The Volvo manual DOES not specify how to do this (only says that a trained Volvo technician can do it) and VIDA only says to pull the console downward. I'll attach some pictures to show you how it's done - I didn't want to break my new ride so I hesitated whether to change the courtesy lightning on my own.
If the console has never been removed you NEED to apply some force to remove it. Don't worry about breaking the console - this should not happen.

The transparent plastic cover can be removed by teasing it out with a screwdriver.


After the console has been removed you should see the plastic framework in the roof with ONLY one connector and a few latches. I have marked the connector and one of the latches in the picture.



The console looks like the one in the fourth picture. The problem you'll have with it is that is HAS CUSTOM VOLVO bulb holders. So you need to either buy these from a certified Volvo shop, buy these online on ebay OR do some soldering yourself. I had no time to wait for the bulbs to arrive in a package so I chose the latter option.



Soldering out old bulbs and soldering the new LED lightning in

To remove holder from the console just twist it out. You'll not be able to remove the bulb from the holder easily, however. You need to somehow break the bulb's wires to pull it out.


The rest of the soldering process includes pulling out LED bulbs from their holders and putting them into the old VOLVO's holders, soldering the LED's wires to the old Volvo's metal connectors and putting the holders again into the console.

I leave the decision as whether to buy the holders from ebay or customize them yourself to you.




Tuesday, November 20, 2012

Import postgresql dump file on windows

Importing dump file from pgAdmin III's "restore" option is not intuitive. It can be done easily from console, however. Just call psql from postgres bin directory located in your installation folder.

c:\Program Files\PostgreSQL\9.1\bin\psql --username=your_username --file=your_dump_file.txt --dbname=your_database